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

Apply Type Metadata to Column Children #9391

Merged
merged 4 commits into from
Nov 16, 2021
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
10 changes: 9 additions & 1 deletion python/cudf/cudf/_lib/column.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,17 @@ cdef class Column:
if self.base_children == ():
self._children = ()
else:
self._children = Column.from_unique_ptr(
children = Column.from_unique_ptr(
make_unique[column](self.view())
).base_children
dtypes = [
base_child.dtype for base_child in self.base_children
]
self._children = [
child._with_type_metadata(dtype) for child, dtype in zip(
children, dtypes
)
]
return self._children

def set_base_children(self, value):
Expand Down
30 changes: 10 additions & 20 deletions python/cudf/cudf/tests/test_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def test_dataframe_to_struct():


@pytest.mark.parametrize(
"series, start, end",
"series, slce",
[
(
[
Expand All @@ -216,8 +216,7 @@ def test_dataframe_to_struct():
{},
None,
],
1,
None,
slice(1, None),
),
(
[
Expand All @@ -229,8 +228,7 @@ def test_dataframe_to_struct():
None,
cudf.NA,
],
1,
5,
slice(1, 5),
),
(
[
Expand All @@ -242,22 +240,15 @@ def test_dataframe_to_struct():
None,
cudf.NA,
],
None,
4,
slice(None, 4),
),
([{"a": {"b": 42, "c": -1}}, {"a": {"b": 0, "c": None}}], slice(0, 1)),
],
)
def test_struct_slice(series, start, end):
sr = cudf.Series(series)
if not end:
expected = cudf.Series(series[start:])
assert sr[start:].to_arrow() == expected.to_arrow()
elif not start:
expected = cudf.Series(series[:end])
assert sr[:end].to_arrow() == expected.to_arrow()
else:
expected = cudf.Series(series[start:end])
assert sr[start:end].to_arrow() == expected.to_arrow()
def test_struct_slice(series, slce):
got = cudf.Series(series)[slce]
expected = cudf.Series(series[slce])
assert got.to_arrow() == expected.to_arrow()


def test_struct_slice_nested_struct():
Expand All @@ -268,8 +259,7 @@ def test_struct_slice_nested_struct():

got = cudf.Series(data)[0:1]
expect = cudf.Series(data[0:1])
assert got.__repr__() == expect.__repr__()
assert got.dtype.to_arrow() == expect.dtype.to_arrow()
assert got.to_arrow() == expect.to_arrow()


@pytest.mark.parametrize(
Expand Down