Skip to content

Commit c0a9447

Browse files
iofallpooja-subramaniam
authored andcommitted
BUG: .transform(ngroup) for axis=1 grouper (pandas-dev#50761)
1 parent 4b0eb6a commit c0a9447

File tree

3 files changed

+2
-5
lines changed

3 files changed

+2
-5
lines changed

doc/source/whatsnew/v2.0.0.rst

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

11341135
Reshaping

pandas/core/groupby/groupby.py

+1-1
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

-4
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)