jorisvandenbossche commented on code in PR #43974:
URL: https://github.com/apache/arrow/pull/43974#discussion_r1753445402
##########
python/pyarrow/tests/test_table.py:
##########
@@ -3737,3 +3753,185 @@ def test_recordbatch_non_cpu(cuda_context,
cpu_recordbatch, cuda_recordbatch,
# __dataframe__() test
with pytest.raises(NotImplementedError):
from_dataframe(cuda_recordbatch.__dataframe__())
+
+
+def verify_cuda_table(table, expected_schema):
+ table.validate()
+ assert table.is_cpu is False
+ assert table.num_columns == len(expected_schema.names)
+ assert table.column_names == expected_schema.names
+ assert str(table) in repr(table)
+ for c in table.columns:
+ assert c.is_cpu is False
+ for chunk in c.iterchunks():
+ assert chunk.is_cpu is False
+ assert chunk.device_type == pa.DeviceAllocationType.CUDA
+ assert table.schema == expected_schema
+
+
+def test_table_non_cpu(cuda_context, cpu_table, cuda_table,
+ cuda_arrays, cuda_recordbatch, schema):
+ verify_cuda_table(cuda_table, expected_schema=schema)
+
+ # shape test
+ assert cuda_table.shape == (10, 2)
+
+ # columns() test
+ assert len(cuda_table.columns) == 2
+
+ # add_column(), set_column() test
+ for fn in [cuda_table.add_column, cuda_table.set_column]:
+ col = pa.array([1] * cuda_table.num_rows, pa.int8()
+ ).copy_to(cuda_context.memory_manager)
+ new_table = fn(2, 'c2', col)
+ verify_cuda_table(new_table, expected_schema=schema.append(
+ pa.field('c2', pa.int8())))
+
+ # remove_column() test
+ new_table = cuda_table.remove_column(1)
+ verify_cuda_table(new_table, expected_schema=schema.remove(1))
+
+ # drop_columns() test
+ new_table = cuda_table.drop_columns(['c1'])
+ verify_cuda_table(new_table, expected_schema=schema.remove(1))
+
+ # select() test
+ new_table = cuda_table.select(['c0'])
+ verify_cuda_table(new_table, expected_schema=schema.remove(1))
+
+ # cast() test
+ new_schema = pa.schema([pa.field('c0', pa.int64()), pa.field('c1',
pa.int64())])
+ with pytest.raises(NotImplementedError):
+ cuda_table.cast(new_schema)
+
+ # drop_null() test
+ null_col = pa.array([1] * cuda_table.num_rows,
+ mask=[True] * cuda_table.num_rows).copy_to(
+ cuda_context.memory_manager)
+ cuda_table_with_nulls = cuda_table.add_column(2, 'c2', null_col)
+ with pytest.raises(NotImplementedError):
+ cuda_table_with_nulls.drop_null()
+
+ # filter() test
+ with pytest.raises(NotImplementedError):
+ cuda_table.filter([True] * cuda_table.num_rows)
+
+ # take() test
+ with pytest.raises(NotImplementedError):
+ cuda_table.take([0])
+
+ # sort_by() test
+ with pytest.raises(NotImplementedError):
+ cuda_table.sort_by('c0')
+
+ # field() test
+ assert cuda_table.field(0) == schema.field(0)
+ assert cuda_table.field(1) == schema.field(1)
+
+ # equals() test
+ with pytest.raises(NotImplementedError):
+ assert cuda_table.equals(cpu_table)
+
+ # from_arrays() test
+ new_table = pa.Table.from_arrays(cuda_arrays, ['c0', 'c1'])
+ verify_cuda_table(new_table, expected_schema=schema)
+
+ # from_pydict() test
+ new_table = pa.Table.from_pydict({'c0': cuda_arrays[0], 'c1':
cuda_arrays[1]})
+ verify_cuda_table(new_table, expected_schema=schema)
+
+ # from_struct_array() test
+ fields = [schema.field(i) for i in range(len(schema.names))]
+ struct_array = pa.StructArray.from_arrays(cuda_arrays, fields=fields)
+ with pytest.raises(NotImplementedError):
+ pa.Table.from_struct_array(struct_array)
+
+ # from_batches() test
+ new_table = pa.Table.from_batches([cuda_recordbatch, cuda_recordbatch],
schema)
+ verify_cuda_table(new_table, expected_schema=schema)
+
+ # nbytes test
+ with pytest.raises(NotImplementedError):
+ assert cuda_table.nbytes
+
+ # get_total_buffer_size() test
+ with pytest.raises(NotImplementedError):
+ assert cuda_table.get_total_buffer_size()
+
+ # to_pydict() test
+ with pytest.raises(NotImplementedError):
+ cuda_table.to_pydict()
+
+ # to_pylist() test
+ with pytest.raises(NotImplementedError):
+ cuda_table.to_pylist()
+
+ # to_pandas() test
+ with pytest.raises(NotImplementedError):
+ cuda_table.to_pandas()
+
+ # to_struct_array() test
+ with pytest.raises(NotImplementedError):
+ cuda_table.to_struct_array()
+
+ # to_batches() test
+ with pytest.raises(NotImplementedError):
+ cuda_table.to_batches()
Review Comment:
-> https://github.com/apache/arrow/issues/44049
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]