diff --git a/python/cudf/cudf/core/dataframe.py b/python/cudf/cudf/core/dataframe.py index 123f86cc200..8fb9b84d96b 100644 --- a/python/cudf/cudf/core/dataframe.py +++ b/python/cudf/cudf/core/dataframe.py @@ -1548,10 +1548,18 @@ def _concat( cudf.core.index.as_index(out.index._values) ) - # Reassign precision for any decimal cols + # Reassign precision for decimal cols & type schema for struct cols for name, col in out._data.items(): - if isinstance(col, cudf.core.column.Decimal64Column): - col = col._with_type_metadata(tables[0]._data[name].dtype) + if isinstance( + col, + ( + cudf.core.column.Decimal64Column, + cudf.core.column.StructColumn, + ), + ): + out._data[name] = col._with_type_metadata( + tables[0]._data[name].dtype + ) # Reassign index and column names if isinstance(objs[0].columns, pd.MultiIndex): diff --git a/python/cudf/cudf/core/series.py b/python/cudf/cudf/core/series.py index 11166320760..7da3bdbb31e 100644 --- a/python/cudf/cudf/core/series.py +++ b/python/cudf/cudf/core/series.py @@ -1448,10 +1448,11 @@ def _concat(cls, objs, axis=0, index=True): col = concat_columns([o._column for o in objs]) - if isinstance(col, cudf.core.column.Decimal64Column): - col = col._with_type_metadata(objs[0]._column.dtype) - - if isinstance(col, cudf.core.column.StructColumn): + # Reassign precision for decimal cols & type schema for struct cols + if isinstance( + col, + (cudf.core.column.Decimal64Column, cudf.core.column.StructColumn), + ): col = col._with_type_metadata(objs[0].dtype) return cls(data=col, index=index, name=name) diff --git a/python/cudf/cudf/tests/test_repr.py b/python/cudf/cudf/tests/test_repr.py index f8c136b8c2d..82020f30f7c 100644 --- a/python/cudf/cudf/tests/test_repr.py +++ b/python/cudf/cudf/tests/test_repr.py @@ -1475,3 +1475,33 @@ def test_empty_series_name(): gs = cudf.from_pandas(ps) assert ps.__repr__() == gs.__repr__() + + +def test_repr_struct_after_concat(): + df = cudf.DataFrame( + { + "a": cudf.Series( + [ + {"sa": 2056831253}, + {"sa": -1463792165}, + {"sa": 1735783038}, + {"sa": 103774433}, + {"sa": -1413247520}, + ] + * 13 + ), + "b": cudf.Series( + [ + {"sa": {"ssa": 1140062029}}, + None, + {"sa": {"ssa": 1998862860}}, + {"sa": None}, + {"sa": {"ssa": -395088502}}, + ] + * 13 + ), + } + ) + pdf = df.to_pandas() + + assert df.__repr__() == pdf.__repr__()