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

Function test_recordbatch_non_cpu

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

Source from the content-addressed store, hash-verified

3869
3870
3871def test_recordbatch_non_cpu(cuda_context, cpu_recordbatch, cuda_recordbatch,
3872 cuda_arrays, schema):
3873 verify_cuda_recordbatch(cuda_recordbatch, expected_schema=schema)
3874 N = cuda_recordbatch.num_rows
3875
3876 # shape test
3877 assert cuda_recordbatch.shape == (5, 2)
3878
3879 # columns() test
3880 assert len(cuda_recordbatch.columns) == 2
3881
3882 # add_column(), set_column() test
3883 for fn in [cuda_recordbatch.add_column, cuda_recordbatch.set_column]:
3884 col = pa.array([-2, -1, 0, 1, 2], pa.int8()
3885 ).copy_to(cuda_context.memory_manager)
3886 new_batch = fn(2, 'c2', col)
3887 verify_cuda_recordbatch(
3888 new_batch, expected_schema=schema.append(pa.field('c2', pa.int8())))
3889 err_msg = ("Got column on device <DeviceAllocationType.CPU: 1>, "
3890 "but expected <DeviceAllocationType.CUDA: 2>.")
3891 with pytest.raises(TypeError, match=err_msg):
3892 fn(2, 'c2', [1] * N)
3893
3894 # remove_column() test
3895 new_batch = cuda_recordbatch.remove_column(1)
3896 verify_cuda_recordbatch(new_batch, expected_schema=schema.remove(1))
3897
3898 # drop_columns() test
3899 new_batch = cuda_recordbatch.drop_columns(['c1'])
3900 verify_cuda_recordbatch(new_batch, expected_schema=schema.remove(1))
3901 empty_batch = cuda_recordbatch.drop_columns(['c0', 'c1'])
3902 assert len(empty_batch.columns) == 0
3903 assert empty_batch.device_type == pa.DeviceAllocationType.CUDA
3904
3905 # select() test
3906 new_batch = cuda_recordbatch.select(['c0'])
3907 verify_cuda_recordbatch(new_batch, expected_schema=schema.remove(1))
3908
3909 # cast() test
3910 new_schema = pa.schema([pa.field('c0', pa.int64()), pa.field('c1', pa.int64())])
3911 with pytest.raises(NotImplementedError):
3912 cuda_recordbatch.cast(new_schema)
3913
3914 # drop_null() test
3915 null_col = pa.array([1] * N, mask=[True, False, True, False, True]).copy_to(
3916 cuda_context.memory_manager)
3917 cuda_recordbatch_with_nulls = cuda_recordbatch.add_column(2, 'c2', null_col)
3918 with pytest.raises(NotImplementedError):
3919 cuda_recordbatch_with_nulls.drop_null()
3920
3921 # filter() test
3922 with pytest.raises(NotImplementedError):
3923 cuda_recordbatch.filter([True] * N)
3924
3925 # take() test
3926 with pytest.raises(NotImplementedError):
3927 cuda_recordbatch.take([0])
3928

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