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 84f075d2df2d5f8ca833c7b98f556e08b5bad338 Mon Sep 17 00:00:00 2001 From: Steven Rotondo Date: Fri, 15 Jul 2022 11:08:29 -0700 Subject: [PATCH 4/5] TST: Moved test to different file #22558 --- pandas/tests/apply/test_frame_apply.py | 18 ++++++++++++++++++ pandas/tests/util/test_assert_series_equal.py | 18 ------------------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/pandas/tests/apply/test_frame_apply.py b/pandas/tests/apply/test_frame_apply.py index 72a9d8723d34c..ae1cd001179b0 100644 --- a/pandas/tests/apply/test_frame_apply.py +++ b/pandas/tests/apply/test_frame_apply.py @@ -1585,3 +1585,21 @@ def test_apply_on_empty_dataframe(): result = df.head(0).apply(lambda x: max(x["a"], x["b"]), axis=1) expected = Series([]) tm.assert_series_equal(result, expected) + + +@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) diff --git a/pandas/tests/util/test_assert_series_equal.py b/pandas/tests/util/test_assert_series_equal.py index 4e5e45b315fc1..2209bed67325c 100644 --- a/pandas/tests/util/test_assert_series_equal.py +++ b/pandas/tests/util/test_assert_series_equal.py @@ -382,21 +382,3 @@ 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 105c3388d1af0621101955a967ac406571dde43a Mon Sep 17 00:00:00 2001 From: Steven Rotondo Date: Wed, 20 Jul 2022 17:26:28 -0700 Subject: [PATCH 5/5] TST: Changed scalars to 1-element lists --- pandas/tests/apply/test_frame_apply.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/apply/test_frame_apply.py b/pandas/tests/apply/test_frame_apply.py index ae1cd001179b0..1ef0865fff552 100644 --- a/pandas/tests/apply/test_frame_apply.py +++ b/pandas/tests/apply/test_frame_apply.py @@ -1590,8 +1590,8 @@ def test_apply_on_empty_dataframe(): @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}), + ({"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):