Skip to content

BUG: .transform(ngroup) for axis=1 grouper #50761

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -3369,7 +3369,7 @@ def ngroup(self, ascending: bool = True):
dtype: int64
"""
with self._group_selection_context():
index = self._selected_obj.index
index = self._selected_obj._get_axis(self.axis)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get index based on self.axis instead of getting the default axis=0 index.

comp_ids = self.grouper.group_info[0]

dtype: type
Expand Down
4 changes: 0 additions & 4 deletions pandas/tests/groupby/transform/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,6 @@ def test_transform_broadcast(tsframe, ts):
def test_transform_axis_1(request, transformation_func):
# GH 36308

if transformation_func == "ngroup":
msg = "ngroup fails with axis=1: #45986"
request.node.add_marker(pytest.mark.xfail(reason=msg))

df = DataFrame({"a": [1, 2], "b": [3, 4], "c": [5, 6]}, index=["x", "y"])
args = get_groupby_method_args(transformation_func, df)
result = df.groupby([0, 0, 1], axis=1).transform(transformation_func, *args)
Expand Down