Skip to content
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

QST:TypeError: sum() got an unexpected keyword argument 'skipna' #35616

Closed
zanwar369 opened this issue Aug 7, 2020 · 10 comments
Closed

QST:TypeError: sum() got an unexpected keyword argument 'skipna' #35616

zanwar369 opened this issue Aug 7, 2020 · 10 comments
Labels
Duplicate Report Duplicate issue or pull request Groupby

Comments

@zanwar369
Copy link

Got the following error when trying to run a groupby sum after updating to the latest pandas:
TypeError: sum() got an unexpected keyword argument 'skipna'

->for row in Holdings[Holdings.Date>HP].groupby(['a','b','c']).sum(skipna=False)[['Balance','Withdrawal']:
....

@zanwar369 zanwar369 added Needs Triage Issue that has not been reviewed by a pandas team member Usage Question labels Aug 7, 2020
@karuppiah7890
Copy link

karuppiah7890 commented Aug 8, 2020

I just checked the help like this

>>> import pandas
>>> pandas.__version__
'1.1.0'
>>> help(pandas.core.groupby.generic.DataFrameGroupBy.sum)

and got

Help on function sum in module pandas.core.groupby.groupby:

sum(self, numeric_only: bool = True, min_count: int = 0)
    Compute sum of group values.

    Parameters
    ----------
    numeric_only : bool, default True
        Include only float, int, boolean columns. If None, will attempt to use
        everything, then use only numeric data.
    min_count : int, default 0
        The required number of valid values to perform the operation. If fewer
        than ``min_count`` non-NA values are present the result will be NA.

    Returns
    -------
    Series or DataFrame
        Computed sum of values within each group.

Looks like skipna is indeed an invalid / unexpected keyword argument. So, seems like a valid error. I also noticed that skipna didn't exist before too, in the argument list, when I checked version 1.0.0 docs and even the oldest docs from 0.20.3

Web docs reference - https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.GroupBy.sum.html

@karuppiah7890
Copy link

@zanwar369 ^

@zanwar369
Copy link
Author

I just checked the help like this

>>> import pandas
>>> pandas.__version__
'1.1.0'
>>> help(pandas.core.groupby.generic.DataFrameGroupBy.sum)

and got

Help on function sum in module pandas.core.groupby.groupby:

sum(self, numeric_only: bool = True, min_count: int = 0)
    Compute sum of group values.

    Parameters
    ----------
    numeric_only : bool, default True
        Include only float, int, boolean columns. If None, will attempt to use
        everything, then use only numeric data.
    min_count : int, default 0
        The required number of valid values to perform the operation. If fewer
        than ``min_count`` non-NA values are present the result will be NA.

    Returns
    -------
    Series or DataFrame
        Computed sum of values within each group.

Looks like skipna is indeed an invalid / unexpected keyword argument. So, seems like a valid error. I also noticed that skipna didn't exist before too, in the argument list, when I checked version 1.0.0 docs and even the oldest docs from 0.20.3

Web docs reference - https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.GroupBy.sum.html

Hmm interesting--thank you! Does anyone know why this was removed? It was functioning in previous versions perfectly

@karuppiah7890
Copy link

karuppiah7890 commented Aug 8, 2020

That's weird. I don't know, it feels like the previous versions didn't have this. Could you tell which version you used that had this? So that it can be confirmed? Maybe the old docs just didn't reflect what was in the code

@zanwar369
Copy link
Author

Sorry for the delay-- it works perfectly on 0.25.3
Looks like it stopped in version 1.0.0. i was utilizing this since I noticed a distinct difference in sums, for very large calculations with and without this qualifier.

@karuppiah7890
Copy link

Ah okay

@simonjayhawkins
Copy link
Member

Thanks @zanwar369 for the question. I think is is covered by #29481, see #29481 (comment) for a workaround

@simonjayhawkins simonjayhawkins removed the Needs Triage Issue that has not been reviewed by a pandas team member label Aug 11, 2020
@zanwar369
Copy link
Author

Thanks @zanwar369 for the question. I think is is covered by #29481, see #29481 (comment) for a workaround

Is there an actual fix in the works? Confused as to why it was removed in the first place

@alimcmaster1 alimcmaster1 self-assigned this Sep 2, 2020
@jorisvandenbossche jorisvandenbossche added Duplicate Report Duplicate issue or pull request Groupby and removed Usage Question labels Nov 20, 2020
@jorisvandenbossche
Copy link
Member

The underlying issue here is that the skipna keyword is at the moment not yet implemented for groupby reductions like groupby(..).sum().

It might be that before this keyword was ignored and recently started to raise, but it never actually worked (or was never documented).

The improvement to add skipna to the grouped reductions is covered in #15675, so going to close this issues.

@jorisvandenbossche
Copy link
Member

Duplicate of #15675

@jorisvandenbossche jorisvandenbossche marked this as a duplicate of #15675 Nov 20, 2020
@jorisvandenbossche jorisvandenbossche added this to the No action milestone Nov 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request Groupby
Projects
None yet
Development

No branches or pull requests

5 participants