From e003b80a8185ad7bceb8824a05fe8db803472922 Mon Sep 17 00:00:00 2001 From: Yuanhao Geng <41546976+GYHHAHA@users.noreply.github.com> Date: Thu, 14 Jul 2022 22:39:35 -0500 Subject: [PATCH 1/3] Update test_function.py --- pandas/tests/groupby/test_function.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pandas/tests/groupby/test_function.py b/pandas/tests/groupby/test_function.py index 7d6c5310942e2..b8905286b449c 100644 --- a/pandas/tests/groupby/test_function.py +++ b/pandas/tests/groupby/test_function.py @@ -1505,3 +1505,15 @@ def test_groupby_empty_dataset(dtype, kwargs): expected = df.groupby("A").B.describe(**kwargs).reset_index(drop=True).iloc[:0] expected.index = Index([]) tm.assert_frame_equal(result, expected) + + +def test_corrwith_with_1_axis(): + # GH 47723 + df = DataFrame({"a": [1, 1, 2], "b": [3, 7, 4]}) + result = df.groupby("a").corrwith(df, axis=1) + index = pd.Index( + data=[(1, 0), (1, 1), (1, 2), (2, 2), (2, 0), (2, 1)], + name=("a", None), + ) + expected = Series([np.nan] * 6, index=index) + tm.assert_series_equal(result, expected) From a45a3afd9643784f582189f3ea82f7a92f9f6f70 Mon Sep 17 00:00:00 2001 From: Yuanhao Geng <41546976+GYHHAHA@users.noreply.github.com> Date: Thu, 14 Jul 2022 22:40:33 -0500 Subject: [PATCH 2/3] Update groupby.py --- pandas/core/groupby/groupby.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 89e47af4cb614..b44db88723742 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -1024,7 +1024,7 @@ def curried(x): curried, self._obj_with_exclusions, is_transform=is_transform ) - if self._selected_obj.ndim != 1 and self.axis != 1: + if self._selected_obj.ndim != 1 and self.axis != 1 and result.ndim != 1: missing = self._obj_with_exclusions.columns.difference(result.columns) if len(missing) > 0: warn_dropping_nuisance_columns_deprecated( From 9c4aaa5e92b84ac3b8c07304419bd2b921423c64 Mon Sep 17 00:00:00 2001 From: Yuanhao Geng <41546976+GYHHAHA@users.noreply.github.com> Date: Thu, 14 Jul 2022 22:51:17 -0500 Subject: [PATCH 3/3] fix flake --- pandas/tests/groupby/test_function.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/groupby/test_function.py b/pandas/tests/groupby/test_function.py index b8905286b449c..de2ff20ff3a96 100644 --- a/pandas/tests/groupby/test_function.py +++ b/pandas/tests/groupby/test_function.py @@ -1511,7 +1511,7 @@ def test_corrwith_with_1_axis(): # GH 47723 df = DataFrame({"a": [1, 1, 2], "b": [3, 7, 4]}) result = df.groupby("a").corrwith(df, axis=1) - index = pd.Index( + index = Index( data=[(1, 0), (1, 1), (1, 2), (2, 2), (2, 0), (2, 1)], name=("a", None), )