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

Convert Column Name to String Before Using Struct Column Factory #10156

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion python/cudf/cudf/core/column/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -1665,7 +1665,7 @@ def build_struct_column(
"""
if dtype is None:
dtype = StructDtype(
fields={name: col.dtype for name, col in zip(names, children)}
fields={str(name): col.dtype for name, col in zip(names, children)}
)

result = build_column(
Expand Down
7 changes: 7 additions & 0 deletions python/cudf/cudf/tests/test_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ def test_dataframe_to_struct():
df["a"][0] = 5
assert_eq(got, expect)

# check that a non-string (but convertible to string) named column can be
# converted to struct
df = cudf.DataFrame([[1, 2], [3, 4]], columns=[(1, "b"), 0])
expect = cudf.Series([{"(1, 'b')": 1, "0": 2}, {"(1, 'b')": 3, "0": 4}])
got = df.to_struct()
assert_eq(got, expect)


@pytest.mark.parametrize(
"series, slce",
Expand Down