Skip to content

DEPR: Add note to groupby docstring about deprecation of axis=1 #54873

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

Closed
rhshadrach opened this issue Aug 30, 2023 · 3 comments · Fixed by #54896
Closed

DEPR: Add note to groupby docstring about deprecation of axis=1 #54873

rhshadrach opened this issue Aug 30, 2023 · 3 comments · Fixed by #54896
Assignees
Labels
Deprecate Functionality to remove in pandas Docs good first issue Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@rhshadrach
Copy link
Member

rhshadrach commented Aug 30, 2023

Ref: #51395 (comment)

The docstring of both DataFrame.groupby and Series.groupby should be updated to indicate the deprecation. Marking as a regression to make clear this goes into 2.1.1.

@rhshadrach rhshadrach added Docs Regression Functionality that used to work in a prior pandas version Deprecate Functionality to remove in pandas good first issue labels Aug 30, 2023
@rhshadrach rhshadrach added this to the 2.1.1 milestone Aug 30, 2023
@rsm-23
Copy link
Contributor

rsm-23 commented Aug 30, 2023

take

@blaiseli
Copy link

I saw a deprecation warning when running some unittest code of mine containing a groupby with axis=1, so I tried to run it with the only slight modification suggested (i.e. transposing my DataFrame and running groupby on it without axis, and now my code fails.

    # This works but issues a deprecation warning:
    #zero_counts_in_a_sample = (counts.groupby(
    #    level=[
    #        i for i in range(len(counts.columns.names))
    #        if i != counts.columns.names.index("count")],
    #    axis=1).sum() == 0.0).any(axis=1)
    # This fails
    zero_counts_in_a_sample = (counts.T.groupby(
        level=[
            i for i in range(len(counts.columns.names))
            if i != counts.columns.names.index("count")]).sum() == 0.0).any(axis=1)

The error is as follows:

Traceback (most recent call last):
  File "/home/bli/src/libsnp/./tests/test_libsnp.py", line 65, in test_concat_data
    counts = concat_counts_from_dicts(self.counts_dict)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/bli/src/libsnp/src/libsnp/libsnp.py", line 116, in concat_counts_from_dicts
    counts = counts.loc[~zero_counts_in_a_sample]
             ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/bli/src/libsnp/.venv/lib/python3.11/site-packages/pandas/core/indexing.py", line 1153, in __getitem__
    return self._getitem_axis(maybe_callable, axis=axis)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/bli/src/libsnp/.venv/lib/python3.11/site-packages/pandas/core/indexing.py", line 1375, in _getitem_axis
    return self._getbool_axis(key, axis=axis)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/bli/src/libsnp/.venv/lib/python3.11/site-packages/pandas/core/indexing.py", line 1171, in _getbool_axis
    key = check_bool_indexer(labels, key)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/bli/src/libsnp/.venv/lib/python3.11/site-packages/pandas/core/indexing.py", line 2575, in check_bool_indexer
    raise IndexingError(
pandas.errors.IndexingError: Unalignable boolean Series provided as indexer (index of the boolean Series and of the indexed object do not match).

So I believe the deprecation explanation should provide more details regarding what to do.

@blaiseli
Copy link

The comment here helped me solve my issue:
#51203 (comment)

I suggest the docstring as well as the deprecation warning mention the back-transposition necessary to obtain functionally equivalent code:

DataFrame.groupby with axis=1 is deprecated. Do frame.T.groupby(...).<insert your operation here>(...).T without axis instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Deprecate Functionality to remove in pandas Docs good first issue Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants