-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DEPR: scalar index for length-1-list level groupby #51817
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
DEPR: scalar index for length-1-list level groupby #51817
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! This PR doesn't deprecate the behavior, it changes the behavior.
We need to first warn users that the behavior will change without changing the current behavior.
Well that's very reasonable, should have thought of that... What's the best way to go about this? Maybe just make a new PR (with an actual "depreciation") and then leave/close this branch so that it can be used for reference when the time is right? |
I would suggest just modifying this PR to deprecate the behavior; as you've already demonstrated the changes to enforce that deprecation won't be extensive. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks good! Some questions / requests.
…august-tengland/pandas-august-tengland into single-element-level-argument-iteration
I'm not sure how to resolve this failing mypy check, using |
Looks okay to add a type ignore here. We should eventually use a type guard with is_list_like but might now be able to do that just yet. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
@pytest.mark.parametrize( | ||
"level_arg, multiindex", [([0], False), ((0,), False), ([0], True), ((0,), True)] | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a small enough case that it is perfectly fine as-is, but wanted to mention that you can stack parameterizations and it will take the cartesian product:
@pytest.mark.parametrize("level_arg", [[0], (0,)])
@pytest.mark.parametrize("multiindex", [False, True])
Thanks @august-tengland! |
groupby
with multi-index #51583doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.Previously, iterating over a Groupby object that had been initialized with a length-1-list
level
parameter (ex. level = [0]) would return scalar indexes as opposed to tuples with only the first element defined (ex. 0 as opposed to (0, ) ). This behavior differs from when using theby
parameter and so the change is motivated.