Skip to content

Commit

Permalink
Fix concatenating structs (#8811)
Browse files Browse the repository at this point in the history
Closes #8802. Currently, when struct series are concatenated, the resulting fields are reset, this PR addresses this by reconstructing the fields once the concatenated series is returned.

Authors:
  - https://github.com/shaneding

Approvers:
  - GALI PREM SAGAR (https://github.com/galipremsagar)
  - Charles Blackmon-Luca (https://github.com/charlesbluca)

URL: #8811
  • Loading branch information
shaneding authored Jul 21, 2021
1 parent cdcc91c commit b43efad
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions python/cudf/cudf/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2433,6 +2433,9 @@ def _concat(cls, objs, axis=0, index=True):
if isinstance(col, cudf.core.column.Decimal64Column):
col = col._with_type_metadata(objs[0]._column.dtype)

if isinstance(col, cudf.core.column.StructColumn):
col = col._with_type_metadata(objs[0].dtype)

return cls(data=col, index=index, name=name)

@property
Expand Down
23 changes: 23 additions & 0 deletions python/cudf/cudf/tests/test_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1527,3 +1527,26 @@ def test_concat_decimal_numeric_series(s1, s2, s3, expected):
def test_concat_decimal_non_numeric(s1, s2, expected):
s = gd.concat([s1, s2])
assert_eq(s, expected)


@pytest.mark.parametrize(
"s1, s2, expected",
[
(
gd.Series([{"a": 5}, {"c": "hello"}, {"b": 7}]),
gd.Series([{"a": 5, "c": "hello", "b": 7}]),
gd.Series(
[
{"a": 5, "b": None, "c": None},
{"a": None, "b": None, "c": "hello"},
{"a": None, "b": 7, "c": None},
{"a": 5, "b": 7, "c": "hello"},
],
index=[0, 1, 2, 0],
),
)
],
)
def test_concat_struct_column(s1, s2, expected):
s = gd.concat([s1, s2])
assert_eq(s, expected)

0 comments on commit b43efad

Please sign in to comment.