Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pylibcudf to_arrow with multiple nested data types #17504

Merged
merged 4 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions python/pylibcudf/pylibcudf/interop.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,19 @@ cdef void _release_array(object array_capsule) noexcept:
free(array)


def _maybe_create_nested_column_metadata(Column col):
return ColumnMetadata(
children_meta=[
_maybe_create_nested_column_metadata(child) for child in col.children()
]
)


def _table_to_schema(Table tbl, metadata):
if metadata is None:
metadata = [ColumnMetadata() for _ in range(len(tbl.columns()))]
metadata = [ColumnMetadata(m) if isinstance(m, str) else m for m in metadata]
metadata = [_maybe_create_nested_column_metadata(col) for col in tbl.columns()]
else:
metadata = [ColumnMetadata(m) if isinstance(m, str) else m for m in metadata]

cdef vector[column_metadata] c_metadata
c_metadata.reserve(len(metadata))
Expand Down
22 changes: 22 additions & 0 deletions python/pylibcudf/pylibcudf/tests/test_interop.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,28 @@ def test_struct_dtype_roundtrip():
assert arrow_type == struct_type


def test_table_with_nested_dtype_to_arrow():
pa_array = pa.array([[{"": 1}]])
plc_table = plc.Table([plc.interop.from_arrow(pa_array)])
result = plc.interop.to_arrow(plc_table)
expected_schema = pa.schema(
[
pa.field(
"",
pa.list_(
pa.field(
"",
pa.struct([pa.field("", pa.int64(), nullable=False)]),
nullable=False,
)
),
nullable=False,
)
]
)
assert result.schema == expected_schema


def test_decimal128_roundtrip():
decimal_type = pa.decimal128(10, 2)
plc_type = plc.interop.from_arrow(decimal_type)
Expand Down
Loading