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.

ENH: Unify API of groupby.sum and sum

See original GitHub issue

Is your feature request related to a problem?

The level keyword in sum is marked as deprecated, but the suggested replacement with groupby.sum does not support skipna, therefore, some behaviours are impossible to replicate easily.

Describe the solution you’d like

grouby.sum should accept the skipna=False keyword,

API breaking implications

Currently the API is inconsistent, since df.sum(axis=1, level=0, skipna=False) has no equivalent since df.groupby(axis=1, level=0).sum(skipna=False) is not available.

Describe alternatives you’ve considered

One can of course do: df.groupby(axis=1, level=0).apply(lambda x : x.sum(axis=1, skipna=False)) but this cannot be the intended use.

Additional context

image

# Your code here, if applicable

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
jrebackcommented, Apr 9, 2022

i am +1 in unifying signatures between aggregators

this is a footgun that we can easily prevent

being efficient for a non default keyword doesn’t matter that much. api consistency is much more important

0reactions
simonjayhawkinscommented, Apr 9, 2022

and if you could add some references to support the discussion and other readers that’ll be great too. e.g. the deprecation and alternatives, where this was discussed etc.

the deprecation was discussed in #39983 and implemented in #40869 and introduced in pandas 1.3

the issue here has already been communicated (with a copy and paste-able code sample) in https://github.com/pandas-dev/pandas/issues/39983#issuecomment-916549939

It is too late now that we are on pandas 1.4.x to undo the deprecation until an appropriate less verbose alternative is available.

there is already an issue to enable skipna on groupby reduction ops #15675, so I think safe to close this as a duplicate.

@phil20686 Thanks for the report. please continue to contribute to the discussion at #15675 instead.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ENH: Unify API of groupby.sum and sum - GitHub
Flexible and powerful data analysis / manipulation library for Python, providing labeled data structures similar to R data.frame objects, ...
Read more >
Pandas groupby() and sum() With Examples
groupby () function returns a DataFrameGroupBy object which contains an aggregate function sum() to calculate a sum of a given column for each ......
Read more >
pandas GroupBy columns with NaN (missing) values
with NA df.groupby('b', dropna=False).sum() a c b 1.0 2 3 2.0 2 5 NaN 1 4 ... merge unique index on dataframe...
Read more >
Pandas Groupby and Sum - GeeksforGeeks
Here, we can apply a group on multiple columns and calculate a sum over each combination group. Python3. Python3 ...
Read more >
Lodash Documentation
groupBy · _.includes · _.invokeMap · _.keyBy · _.map · _. ... minBy · _.multiply · _.round · _.subtract · _.sum · _.sumBy...
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