-
-
Notifications
You must be signed in to change notification settings - Fork 18k
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
BUG: DataFrameGroupBy.__getitem__ should warn on tuple of length 1 #36302
Comments
I didn't notice that in the whatsnew of PR #30546 there are the lines:
This makes me think that perhaps it wasn't due to any confusion. However, I don't see any mention of tuples of length one in the original issue #23566 and allowing only tuples of length one seems odd to me. @jorisvandenbossche Any thoughts? |
This is also inconsistent with DataFrame, e.g.
raises |
Is there any interest in making the df = pd.DataFrame(...)
df_gb = df.groupby("A")
# Passing a tuple returns the Series for the column matching that MultiIndex tuple representation
s: pd.Series = df[("B", "1")]
# Passing a tuple *should* return the SeriesGroupBy for the column matching that MultiIndex tuple representation
s_gb: pd.SeriesGroupBy = df_gb[("B", "1")]
# This should be equivalent
s_gb_equiv: pd.SeriesGroupBy = s.groupby(df["A"]) Currently, it doesn't seem like there's really any way to reduce a |
I think so @tehunter. E.g. this works just fine:
and will continue to work fine under your proposed behavior. We still need to deprecate the case where you are passing a tuple and the columns are not a MultiIndex nor tuples, so this issue needs to remain, but we can enable your desired behavior without waiting for that deprecation. Could you open up a separate issue? |
Thanks, just opened #58282 |
Currently warnings are only emitted when the length of a tuple is greater than 1. From this comment in PR where the deprecation was implemented, there was some confusion as to the behavior of
df.groupby('a')['b']
vsdf.groupby('a')[('b', )]
. The former is the SeriesGroupBy that the comment refers to wherekey
is a string, the latter should still be deprecated.The text was updated successfully, but these errors were encountered: