MCPcopy Create free account
hub / github.com/apache/arrow / test_recordbatch_non_cpu

Function test_recordbatch_non_cpu

python/pyarrow/tests/test_table.py:3706–3863  ·  view source on GitHub ↗
(cuda_context, cpu_recordbatch, cuda_recordbatch,
                             cuda_arrays, schema)

Source from the content-addressed store, hash-verified

3704
3705
3706def test_recordbatch_non_cpu(cuda_context, cpu_recordbatch, cuda_recordbatch,
3707 cuda_arrays, schema):
3708 verify_cuda_recordbatch(cuda_recordbatch, expected_schema=schema)
3709 N = cuda_recordbatch.num_rows
3710
3711 # shape test
3712 assert cuda_recordbatch.shape == (5, 2)
3713
3714 # columns() test
3715 assert len(cuda_recordbatch.columns) == 2
3716
3717 # add_column(), set_column() test
3718 for fn in [cuda_recordbatch.add_column, cuda_recordbatch.set_column]:
3719 col = pa.array([-2, -1, 0, 1, 2], pa.int8()
3720 ).copy_to(cuda_context.memory_manager)
3721 new_batch = fn(2, 'c2', col)
3722 verify_cuda_recordbatch(
3723 new_batch, expected_schema=schema.append(pa.field('c2', pa.int8())))
3724 err_msg = ("Got column on device <DeviceAllocationType.CPU: 1>, "
3725 "but expected <DeviceAllocationType.CUDA: 2>.")
3726 with pytest.raises(TypeError, match=err_msg):
3727 fn(2, 'c2', [1] * N)
3728
3729 # remove_column() test
3730 new_batch = cuda_recordbatch.remove_column(1)
3731 verify_cuda_recordbatch(new_batch, expected_schema=schema.remove(1))
3732
3733 # drop_columns() test
3734 new_batch = cuda_recordbatch.drop_columns(['c1'])
3735 verify_cuda_recordbatch(new_batch, expected_schema=schema.remove(1))
3736 empty_batch = cuda_recordbatch.drop_columns(['c0', 'c1'])
3737 assert len(empty_batch.columns) == 0
3738 assert empty_batch.device_type == pa.DeviceAllocationType.CUDA
3739
3740 # select() test
3741 new_batch = cuda_recordbatch.select(['c0'])
3742 verify_cuda_recordbatch(new_batch, expected_schema=schema.remove(1))
3743
3744 # cast() test
3745 new_schema = pa.schema([pa.field('c0', pa.int64()), pa.field('c1', pa.int64())])
3746 with pytest.raises(NotImplementedError):
3747 cuda_recordbatch.cast(new_schema)
3748
3749 # drop_null() test
3750 null_col = pa.array([1] * N, mask=[True, False, True, False, True]).copy_to(
3751 cuda_context.memory_manager)
3752 cuda_recordbatch_with_nulls = cuda_recordbatch.add_column(2, 'c2', null_col)
3753 with pytest.raises(NotImplementedError):
3754 cuda_recordbatch_with_nulls.drop_null()
3755
3756 # filter() test
3757 with pytest.raises(NotImplementedError):
3758 cuda_recordbatch.filter([True] * N)
3759
3760 # take() test
3761 with pytest.raises(NotImplementedError):
3762 cuda_recordbatch.take([0])
3763

Callers

nothing calls this directly

Calls 15

from_dataframeFunction · 0.90
verify_cuda_recordbatchFunction · 0.85
lenFunction · 0.85
filterMethod · 0.80
equalsMethod · 0.80
__dataframe__Method · 0.80
arrayMethod · 0.45
appendMethod · 0.45
fieldMethod · 0.45
remove_columnMethod · 0.45
selectMethod · 0.45
schemaMethod · 0.45

Tested by

no test coverage detected