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

Function test_recordbatch_non_cpu

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

Source from the content-addressed store, hash-verified

3815
3816
3817def test_recordbatch_non_cpu(cuda_context, cpu_recordbatch, cuda_recordbatch,
3818 cuda_arrays, schema):
3819 verify_cuda_recordbatch(cuda_recordbatch, expected_schema=schema)
3820 N = cuda_recordbatch.num_rows
3821
3822 # shape test
3823 assert cuda_recordbatch.shape == (5, 2)
3824
3825 # columns() test
3826 assert len(cuda_recordbatch.columns) == 2
3827
3828 # add_column(), set_column() test
3829 for fn in [cuda_recordbatch.add_column, cuda_recordbatch.set_column]:
3830 col = pa.array([-2, -1, 0, 1, 2], pa.int8()
3831 ).copy_to(cuda_context.memory_manager)
3832 new_batch = fn(2, 'c2', col)
3833 verify_cuda_recordbatch(
3834 new_batch, expected_schema=schema.append(pa.field('c2', pa.int8())))
3835 err_msg = ("Got column on device <DeviceAllocationType.CPU: 1>, "
3836 "but expected <DeviceAllocationType.CUDA: 2>.")
3837 with pytest.raises(TypeError, match=err_msg):
3838 fn(2, 'c2', [1] * N)
3839
3840 # remove_column() test
3841 new_batch = cuda_recordbatch.remove_column(1)
3842 verify_cuda_recordbatch(new_batch, expected_schema=schema.remove(1))
3843
3844 # drop_columns() test
3845 new_batch = cuda_recordbatch.drop_columns(['c1'])
3846 verify_cuda_recordbatch(new_batch, expected_schema=schema.remove(1))
3847 empty_batch = cuda_recordbatch.drop_columns(['c0', 'c1'])
3848 assert len(empty_batch.columns) == 0
3849 assert empty_batch.device_type == pa.DeviceAllocationType.CUDA
3850
3851 # select() test
3852 new_batch = cuda_recordbatch.select(['c0'])
3853 verify_cuda_recordbatch(new_batch, expected_schema=schema.remove(1))
3854
3855 # cast() test
3856 new_schema = pa.schema([pa.field('c0', pa.int64()), pa.field('c1', pa.int64())])
3857 with pytest.raises(NotImplementedError):
3858 cuda_recordbatch.cast(new_schema)
3859
3860 # drop_null() test
3861 null_col = pa.array([1] * N, mask=[True, False, True, False, True]).copy_to(
3862 cuda_context.memory_manager)
3863 cuda_recordbatch_with_nulls = cuda_recordbatch.add_column(2, 'c2', null_col)
3864 with pytest.raises(NotImplementedError):
3865 cuda_recordbatch_with_nulls.drop_null()
3866
3867 # filter() test
3868 with pytest.raises(NotImplementedError):
3869 cuda_recordbatch.filter([True] * N)
3870
3871 # take() test
3872 with pytest.raises(NotImplementedError):
3873 cuda_recordbatch.take([0])
3874

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