From 0097f751c4af38107ffa31c5e19b90b6d88f045a Mon Sep 17 00:00:00 2001 From: Steven Rotondo Date: Tue, 5 Jul 2022 15:43:34 -0700 Subject: [PATCH 1/5] TST: Added test for consistent type with unique agg #22558 --- pandas/tests/groupby/aggregate/test_aggregate.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pandas/tests/groupby/aggregate/test_aggregate.py b/pandas/tests/groupby/aggregate/test_aggregate.py index d52b6ceaf8990..47a77f5801af6 100644 --- a/pandas/tests/groupby/aggregate/test_aggregate.py +++ b/pandas/tests/groupby/aggregate/test_aggregate.py @@ -1413,3 +1413,15 @@ def test_multi_axis_1_raises(func): gb = df.groupby("a", axis=1) with pytest.raises(NotImplementedError, match="axis other than 0 is not supported"): gb.agg(func) + + +def test_unique_agg_type(): + # GH#22558 + df1 = DataFrame({"a": [1, 2, 3], "b": [1, 1, 1]}) + df2 = DataFrame({"a": [2, 2, 2], "b": [1, 1, 1]}) + aggregation = {"a": "unique", "b": "unique"} + + agg1 = df1.agg(aggregation) + agg2 = df2.agg(aggregation) + + tm.assert_class_equal(agg1, agg2) From 06db464d458bd4771f56fcb14b75a1d0e62d4bdd Mon Sep 17 00:00:00 2001 From: Steven Rotondo Date: Tue, 5 Jul 2022 16:13:52 -0700 Subject: [PATCH 2/5] TST: Added test for consistent type with unique agg #22558 --- pandas/tests/groupby/aggregate/test_aggregate.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pandas/tests/groupby/aggregate/test_aggregate.py b/pandas/tests/groupby/aggregate/test_aggregate.py index 54ee32502bbc9..d9dbd32974d3c 100644 --- a/pandas/tests/groupby/aggregate/test_aggregate.py +++ b/pandas/tests/groupby/aggregate/test_aggregate.py @@ -1438,3 +1438,15 @@ def test_agg_of_mode_list(test, constant): expected = expected.set_index(0) tm.assert_frame_equal(result, expected) + + +def test_unique_agg_type(): + # GH#22558 + df1 = DataFrame({"a": [1, 2, 3], "b": [1, 1, 1]}) + df2 = DataFrame({"a": [2, 2, 2], "b": [1, 1, 1]}) + aggregation = {"a": "unique", "b": "unique"} + + agg1 = df1.agg(aggregation) + agg2 = df2.agg(aggregation) + + tm.assert_class_equal(agg1, agg2) From f977a15580edbe9ebd0d9da86e748c7b6e1f08a9 Mon Sep 17 00:00:00 2001 From: Steven Rotondo Date: Wed, 6 Jul 2022 12:35:30 -0700 Subject: [PATCH 3/5] TST: Moved and restructured test #22558 --- .../tests/groupby/aggregate/test_aggregate.py | 12 ------------ pandas/tests/util/test_assert_series_equal.py | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/pandas/tests/groupby/aggregate/test_aggregate.py b/pandas/tests/groupby/aggregate/test_aggregate.py index d9dbd32974d3c..54ee32502bbc9 100644 --- a/pandas/tests/groupby/aggregate/test_aggregate.py +++ b/pandas/tests/groupby/aggregate/test_aggregate.py @@ -1438,15 +1438,3 @@ def test_agg_of_mode_list(test, constant): expected = expected.set_index(0) tm.assert_frame_equal(result, expected) - - -def test_unique_agg_type(): - # GH#22558 - df1 = DataFrame({"a": [1, 2, 3], "b": [1, 1, 1]}) - df2 = DataFrame({"a": [2, 2, 2], "b": [1, 1, 1]}) - aggregation = {"a": "unique", "b": "unique"} - - agg1 = df1.agg(aggregation) - agg2 = df2.agg(aggregation) - - tm.assert_class_equal(agg1, agg2) diff --git a/pandas/tests/util/test_assert_series_equal.py b/pandas/tests/util/test_assert_series_equal.py index 2209bed67325c..4e5e45b315fc1 100644 --- a/pandas/tests/util/test_assert_series_equal.py +++ b/pandas/tests/util/test_assert_series_equal.py @@ -382,3 +382,21 @@ def test_assert_series_equal_identical_na(nulls_fixture): # while we're here do Index too idx = pd.Index(ser) tm.assert_index_equal(idx, idx.copy(deep=True)) + + +@pytest.mark.parametrize( + "test, constant", + [ + ({"a": [1, 2, 3], "b": [1, 1, 1]}, {"a": [1, 2, 3], "b": 1}), + ({"a": [2, 2, 2], "b": [1, 1, 1]}, {"a": 2, "b": 1}), + ], +) +def test_unique_agg_type_is_series(test, constant): + # GH#22558 + df1 = DataFrame(test) + expected = Series(data=constant, index=["a", "b"], dtype="object") + aggregation = {"a": "unique", "b": "unique"} + + result = df1.agg(aggregation) + + tm.assert_series_equal(result, expected) From d648cbd75ba230c3ab8d457db796ab5ff72185aa Mon Sep 17 00:00:00 2001 From: Steven Rotondo Date: Thu, 7 Jul 2022 13:18:08 -0700 Subject: [PATCH 4/5] TST: Added test for nested series #22400 --- pandas/tests/util/test_assert_series_equal.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/pandas/tests/util/test_assert_series_equal.py b/pandas/tests/util/test_assert_series_equal.py index 4e5e45b315fc1..330f06847a3ff 100644 --- a/pandas/tests/util/test_assert_series_equal.py +++ b/pandas/tests/util/test_assert_series_equal.py @@ -1,3 +1,4 @@ +import numpy as np import pytest from pandas.core.dtypes.common import is_extension_array_dtype @@ -400,3 +401,29 @@ def test_unique_agg_type_is_series(test, constant): result = df1.agg(aggregation) tm.assert_series_equal(result, expected) + + +def test_identical_nested_series_is_equal(): + # GH#22400 + x = Series( + [ + 0, + 0.0131142231938, + 1.77774652865e-05, + np.array([0.4722720840328748, 0.4216929783681722]), + ] + ) + y = Series( + [ + 0, + 0.0131142231938, + 1.77774652865e-05, + np.array([0.4722720840328748, 0.4216929783681722]), + ] + ) + # These two arrays should be equal, nesting could cause issue + + tm.assert_series_equal(x, x) + tm.assert_series_equal(x, x, check_exact=True) + tm.assert_series_equal(x, y) + tm.assert_series_equal(x, y, check_exact=True) From dd8e323dda3a07c8381eff41c19c60c06d852c78 Mon Sep 17 00:00:00 2001 From: Steven Rotondo Date: Thu, 7 Jul 2022 13:22:54 -0700 Subject: [PATCH 5/5] TST: Added equality test for nested series #22400 --- pandas/tests/util/test_assert_series_equal.py | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/pandas/tests/util/test_assert_series_equal.py b/pandas/tests/util/test_assert_series_equal.py index 330f06847a3ff..963af81bcb6a5 100644 --- a/pandas/tests/util/test_assert_series_equal.py +++ b/pandas/tests/util/test_assert_series_equal.py @@ -385,24 +385,6 @@ def test_assert_series_equal_identical_na(nulls_fixture): tm.assert_index_equal(idx, idx.copy(deep=True)) -@pytest.mark.parametrize( - "test, constant", - [ - ({"a": [1, 2, 3], "b": [1, 1, 1]}, {"a": [1, 2, 3], "b": 1}), - ({"a": [2, 2, 2], "b": [1, 1, 1]}, {"a": 2, "b": 1}), - ], -) -def test_unique_agg_type_is_series(test, constant): - # GH#22558 - df1 = DataFrame(test) - expected = Series(data=constant, index=["a", "b"], dtype="object") - aggregation = {"a": "unique", "b": "unique"} - - result = df1.agg(aggregation) - - tm.assert_series_equal(result, expected) - - def test_identical_nested_series_is_equal(): # GH#22400 x = Series(