Skip to content

Grouping by all columns of an empty DataFrame should produce MultiIndex, but doesn't #32464

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
shwina opened this issue Mar 5, 2020 · 4 comments · Fixed by #48067
Closed
Assignees
Labels
good first issue Groupby MultiIndex Needs Tests Unit test(s) needed to prevent regressions
Milestone

Comments

@shwina
Copy link
Contributor

shwina commented Mar 5, 2020

Greetings!

This comes up in cuDF in our tests that check for compatibility with Pandas:

In [21]: a = pd.DataFrame({'a': [], 'b': [], 'c': []})

In [22]: a.groupby(['a', 'b']).sum().index
Out[22]: MultiIndex([], names=['a', 'b'])

In [23]: a.groupby(['a', 'b', 'c']).sum().index
Out[23]: Index([], dtype='object')

Would it be more consistent for grouping by multiple columns to always result in a MultiIndex?

Edit: Checked with Pandas 1.0.1 as well as 0.25.3 -- same behaviour.

@mroeschke
Copy link
Member

Looks to be okay in master now. Could use a test

In [3]: In [21]: a = pd.DataFrame({'a': [], 'b': [], 'c': []})

In [4]: In [22]: a.groupby(['a', 'b']).sum().index
Out[4]: MultiIndex([], names=['a', 'b'])

In [5]: In [23]: a.groupby(['a', 'b', 'c']).sum().index
Out[5]: MultiIndex([], names=['a', 'b', 'c'])

@mroeschke mroeschke added good first issue Needs Tests Unit test(s) needed to prevent regressions labels Jul 29, 2021
@gabrieldi95
Copy link
Contributor

take

gabrieldi95 added a commit to gabrieldi95/pandas that referenced this issue Oct 16, 2021
@jreback jreback added this to the 1.4 milestone Oct 16, 2021
@jreback jreback modified the milestones: 1.4, Contributions Welcome Dec 23, 2021
@jreback jreback modified the milestones: Contributions Welcome, 1.5 Apr 6, 2022
@YagoGG
Copy link
Contributor

YagoGG commented Aug 13, 2022

@gabrieldi95 with your permission, I will be retaking this. Cheers!

@YagoGG
Copy link
Contributor

YagoGG commented Aug 13, 2022

take

YagoGG added a commit to YagoGG/pandas that referenced this issue Aug 13, 2022
YagoGG added a commit to YagoGG/pandas that referenced this issue Aug 13, 2022
YagoGG added a commit to YagoGG/pandas that referenced this issue Aug 13, 2022
YagoGG added a commit to YagoGG/pandas that referenced this issue Aug 14, 2022
mroeschke pushed a commit that referenced this issue Aug 15, 2022
TST: Check MultiIndex when grouping by all columns of an empty DF (#32464)

Co-authored-by: Richard Shadrach
    <[email protected]>

Co-authored-by: Richard Shadrach <[email protected]>
YYYasin19 pushed a commit to YYYasin19/pandas that referenced this issue Aug 23, 2022
) (pandas-dev#48067)

TST: Check MultiIndex when grouping by all columns of an empty DF (pandas-dev#32464)

Co-authored-by: Richard Shadrach
    <[email protected]>

Co-authored-by: Richard Shadrach <[email protected]>
noatamir pushed a commit to noatamir/pandas that referenced this issue Nov 9, 2022
) (pandas-dev#48067)

TST: Check MultiIndex when grouping by all columns of an empty DF (pandas-dev#32464)

Co-authored-by: Richard Shadrach
    <[email protected]>

Co-authored-by: Richard Shadrach <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Groupby MultiIndex Needs Tests Unit test(s) needed to prevent regressions
Projects
None yet
6 participants