Skip to content

Commit 030f870

Browse files
authored
BUG: groupby.corrwith fails with axis=1 and other=df (#47731)
1 parent 87e9c4a commit 030f870

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

pandas/core/groupby/groupby.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ def curried(x):
10241024
curried, self._obj_with_exclusions, is_transform=is_transform
10251025
)
10261026

1027-
if self._selected_obj.ndim != 1 and self.axis != 1:
1027+
if self._selected_obj.ndim != 1 and self.axis != 1 and result.ndim != 1:
10281028
missing = self._obj_with_exclusions.columns.difference(result.columns)
10291029
if len(missing) > 0:
10301030
warn_dropping_nuisance_columns_deprecated(

pandas/tests/groupby/test_function.py

+12
Original file line numberDiff line numberDiff line change
@@ -1505,3 +1505,15 @@ def test_groupby_empty_dataset(dtype, kwargs):
15051505
expected = df.groupby("A").B.describe(**kwargs).reset_index(drop=True).iloc[:0]
15061506
expected.index = Index([])
15071507
tm.assert_frame_equal(result, expected)
1508+
1509+
1510+
def test_corrwith_with_1_axis():
1511+
# GH 47723
1512+
df = DataFrame({"a": [1, 1, 2], "b": [3, 7, 4]})
1513+
result = df.groupby("a").corrwith(df, axis=1)
1514+
index = Index(
1515+
data=[(1, 0), (1, 1), (1, 2), (2, 2), (2, 0), (2, 1)],
1516+
name=("a", None),
1517+
)
1518+
expected = Series([np.nan] * 6, index=index)
1519+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)