From 3d86defc0a1e2ee616aa8f9f1b5950edfd103e78 Mon Sep 17 00:00:00 2001 From: Shane Ding Date: Wed, 21 Jul 2021 15:35:43 +0000 Subject: [PATCH 1/2] fiix concat --- python/cudf/cudf/core/series.py | 3 ++ python/cudf/cudf/tests/test_concat.py | 66 ++++----------------------- 2 files changed, 12 insertions(+), 57 deletions(-) diff --git a/python/cudf/cudf/core/series.py b/python/cudf/cudf/core/series.py index bd54daa25dd..8e9f1127438 100644 --- a/python/cudf/cudf/core/series.py +++ b/python/cudf/cudf/core/series.py @@ -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 diff --git a/python/cudf/cudf/tests/test_concat.py b/python/cudf/cudf/tests/test_concat.py index 2578cb13bff..f07947b7d90 100644 --- a/python/cudf/cudf/tests/test_concat.py +++ b/python/cudf/cudf/tests/test_concat.py @@ -1462,68 +1462,20 @@ def test_concat_decimal_numeric_series(s1, s2, s3, expected): "s1, s2, expected", [ ( - gd.Series( - [Decimal("955.22"), Decimal("8.2")], dtype=Decimal64Dtype(5, 2) - ), - gd.Series(["2007-06-12", "2006-03-14"], dtype="datetime64"), - gd.Series( - [ - "955.22", - "8.20", - "2007-06-12 00:00:00", - "2006-03-14 00:00:00", - ], - index=[0, 1, 0, 1], - ), - ), - ( - gd.Series( - [Decimal("-52.44"), Decimal("365.22")], - dtype=Decimal64Dtype(5, 2), - ), - gd.Series( - np.arange( - "2005-02-01T12", "2005-02-01T15", dtype="datetime64[h]" - ), - dtype="datetime64[s]", - ), + gd.Series([{"a": 5}, {"c": "hello"}, {"b": 7}]), + gd.Series([{"a": 5, "c": "hello", "b": 7}]), gd.Series( [ - "-52.44", - "365.22", - "2005-02-01 12:00:00", - "2005-02-01 13:00:00", - "2005-02-01 14:00:00", + {"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, 0, 1, 2], - ), - ), - ( - gd.Series( - [Decimal("753.0"), Decimal("94.22")], - dtype=Decimal64Dtype(5, 2), - ), - gd.Series([np.timedelta64(111, "s"), np.timedelta64(509, "s")]), - gd.Series( - ["753.00", "94.22", "0 days 00:01:51", "0 days 00:08:29"], - index=[0, 1, 0, 1], - ), - ), - ( - gd.Series( - [Decimal("753.0"), Decimal("94.22")], - dtype=Decimal64Dtype(5, 2), - ), - gd.Series( - [np.timedelta64(940252, "s"), np.timedelta64(758385, "s")] + index=[0, 1, 2, 0], ), - gd.Series( - ["753.00", "94.22", "10 days 21:10:52", "8 days 18:39:45"], - index=[0, 1, 0, 1], - ), - ), + ) ], ) -def test_concat_decimal_non_numeric(s1, s2, expected): +def test_concat_struct_column(s1, s2, expected): s = gd.concat([s1, s2]) assert_eq(s, expected) From 11d896064d180588fa776edd752a5316e13d8d22 Mon Sep 17 00:00:00 2001 From: Shane Ding Date: Wed, 21 Jul 2021 15:41:35 +0000 Subject: [PATCH 2/2] undo deletion to test_concat.py --- python/cudf/cudf/tests/test_concat.py | 71 +++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/python/cudf/cudf/tests/test_concat.py b/python/cudf/cudf/tests/test_concat.py index f07947b7d90..b1b71bd882e 100644 --- a/python/cudf/cudf/tests/test_concat.py +++ b/python/cudf/cudf/tests/test_concat.py @@ -1458,6 +1458,77 @@ def test_concat_decimal_numeric_series(s1, s2, s3, expected): assert_eq(s, expected) +@pytest.mark.parametrize( + "s1, s2, expected", + [ + ( + gd.Series( + [Decimal("955.22"), Decimal("8.2")], dtype=Decimal64Dtype(5, 2) + ), + gd.Series(["2007-06-12", "2006-03-14"], dtype="datetime64"), + gd.Series( + [ + "955.22", + "8.20", + "2007-06-12 00:00:00", + "2006-03-14 00:00:00", + ], + index=[0, 1, 0, 1], + ), + ), + ( + gd.Series( + [Decimal("-52.44"), Decimal("365.22")], + dtype=Decimal64Dtype(5, 2), + ), + gd.Series( + np.arange( + "2005-02-01T12", "2005-02-01T15", dtype="datetime64[h]" + ), + dtype="datetime64[s]", + ), + gd.Series( + [ + "-52.44", + "365.22", + "2005-02-01 12:00:00", + "2005-02-01 13:00:00", + "2005-02-01 14:00:00", + ], + index=[0, 1, 0, 1, 2], + ), + ), + ( + gd.Series( + [Decimal("753.0"), Decimal("94.22")], + dtype=Decimal64Dtype(5, 2), + ), + gd.Series([np.timedelta64(111, "s"), np.timedelta64(509, "s")]), + gd.Series( + ["753.00", "94.22", "0 days 00:01:51", "0 days 00:08:29"], + index=[0, 1, 0, 1], + ), + ), + ( + gd.Series( + [Decimal("753.0"), Decimal("94.22")], + dtype=Decimal64Dtype(5, 2), + ), + gd.Series( + [np.timedelta64(940252, "s"), np.timedelta64(758385, "s")] + ), + gd.Series( + ["753.00", "94.22", "10 days 21:10:52", "8 days 18:39:45"], + index=[0, 1, 0, 1], + ), + ), + ], +) +def test_concat_decimal_non_numeric(s1, s2, expected): + s = gd.concat([s1, s2]) + assert_eq(s, expected) + + @pytest.mark.parametrize( "s1, s2, expected", [