Skip to content

Commit bebfec5

Browse files
authored
Merge branch 'main' into issue-50395
2 parents cf1268a + 33f4f7b commit bebfec5

File tree

3 files changed

+2
-5
lines changed

3 files changed

+2
-5
lines changed

doc/source/whatsnew/v2.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,7 @@ Groupby/resample/rolling
11311131
- Bug in :class:`.DataFrameGroupBy` would raise when used with an empty DataFrame, categorical grouper, and ``dropna=False`` (:issue:`50634`)
11321132
- Bug in :meth:`.SeriesGroupBy.value_counts` did not respect ``sort=False`` (:issue:`50482`)
11331133
- Bug in :meth:`.DataFrameGroupBy.resample` raises ``KeyError`` when getting the result from a key list when resampling on time index (:issue:`50840`)
1134+
- Bug in :meth:`.DataFrameGroupBy.transform` and :meth:`.SeriesGroupBy.transform` would raise incorrectly when grouper had ``axis=1`` for ``"ngroup"`` argument (:issue:`45986`)
11341135
-
11351136

11361137
Reshaping

pandas/core/groupby/groupby.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3394,7 +3394,7 @@ def ngroup(self, ascending: bool = True):
33943394
dtype: int64
33953395
"""
33963396
with self._group_selection_context():
3397-
index = self._selected_obj.index
3397+
index = self._selected_obj._get_axis(self.axis)
33983398
comp_ids = self.grouper.group_info[0]
33993399

34003400
dtype: type

pandas/tests/groupby/transform/test_transform.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,6 @@ def test_transform_broadcast(tsframe, ts):
164164
def test_transform_axis_1(request, transformation_func):
165165
# GH 36308
166166

167-
if transformation_func == "ngroup":
168-
msg = "ngroup fails with axis=1: #45986"
169-
request.node.add_marker(pytest.mark.xfail(reason=msg))
170-
171167
df = DataFrame({"a": [1, 2], "b": [3, 4], "c": [5, 6]}, index=["x", "y"])
172168
args = get_groupby_method_args(transformation_func, df)
173169
result = df.groupby([0, 0, 1], axis=1).transform(transformation_func, *args)

0 commit comments

Comments
 (0)