Skip to content

Commit 83f1365

Browse files
author
Ethan Chen
committed
BUG: DataFrameGroupBy.transform with axis=1 fails (pandas-dev#36308)
1 parent 068d1b5 commit 83f1365

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

pandas/core/groupby/generic.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1676,7 +1676,13 @@ def _wrap_transformed_output(
16761676
columns.name = self.obj.columns.name
16771677

16781678
result = self.obj._constructor(indexed_output)
1679-
result.columns = columns
1679+
1680+
if self.axis == 1:
1681+
result = result.T
1682+
result.columns = self.obj.columns
1683+
else:
1684+
result.columns = columns
1685+
16801686
result.index = self.obj.index
16811687

16821688
return result

pandas/core/groupby/groupby.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2668,8 +2668,8 @@ def pct_change(self, periods=1, fill_method="pad", limit=None, freq=None, axis=0
26682668
fill_method = "pad"
26692669
limit = 0
26702670
filled = getattr(self, fill_method)(limit=limit)
2671-
fill_grp = filled.groupby(self.grouper.codes)
2672-
shifted = fill_grp.shift(periods=periods, freq=freq)
2671+
fill_grp = filled.groupby(self.grouper.codes, axis=self.axis)
2672+
shifted = fill_grp.shift(periods=periods, freq=freq, axis=self.axis)
26732673
return (filled / shifted) - 1
26742674

26752675
@Substitution(name="groupby")

pandas/tests/frame/apply/test_frame_transform.py

-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ def test_transform_groupby_kernel(axis, float_frame, op):
2727
pytest.xfail("DataFrame.cumcount does not exist")
2828
if op == "tshift":
2929
pytest.xfail("Only works on time index and is deprecated")
30-
if axis == 1 or axis == "columns":
31-
pytest.xfail("GH 36308: groupby.transform with axis=1 is broken")
3230

3331
args = [0.0] if op == "fillna" else []
3432
if axis == 0 or axis == "index":

0 commit comments

Comments
 (0)