question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

REGR: 1.3 behavior change with groupby and asindex=False

See original GitHub issue

Code Sample, a copy-pastable example

pd.DataFrame(columns=["date", "crew_member_id"])
    .groupby(["date", "crew_member_id"], as_index=False)
    .sum()

Problem description

With 1.3rc1 this fails with ValueError: Length of values (0) does not match length of index (1) while 1.2 returns and empty frame.

Expected Output

If this is the expected behavior fine. Just wanted to ensure that it is not an accidental regression.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
phoflcommented, Jun 15, 2021

This one fails too:

df = pd.DataFrame(columns=["a", "b"]).groupby(["a"], as_index=False).sum()

The initial code snippet seems a bit artificial to me, mostly because I don’t know what to actually expect. But this one returned

Empty DataFrame
Columns: [a, b]
Index: []

on 1.2.4 which looks sensible to me. Labelling as a regression

0reactions
rhshadrachcommented, Jun 26, 2021

Ah - this path is dropping column ‘b’ because it is object dtype. Doing

print(pd.DataFrame(columns=["a", "b"], dtype=int).groupby(["a"], as_index=False).sum())

gives

Empty DataFrame
Columns: [a, b]
Index: []

which is better. Running tests now, PR to follow.

Read more comments on GitHub >

github_iconTop Results From Across the Web

pandas.DataFrame.groupby — pandas 1.5.2 documentation
A groupby operation involves some combination of splitting the object, applying a function, and combining the results. This can be used to group...
Read more >
Percent Change In Groupby Object by Group - Stack Overflow
I'd like to add a percent change from previous year to a column to the right in this groupby. I tried several methods,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found