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

Improve error message in Series.any and Series.all, when bool_only is passed and not level #38810

Closed
moink opened this issue Dec 30, 2020 · 3 comments
Labels
Bug Error Reporting Incorrect or improved errors from pandas Reduction Operations sum, mean, min, max, etc.

Comments

@moink
Copy link
Member

moink commented Dec 30, 2020

When working on xref #30999 I came across TestSeriesReductions.test_all_any_params in pandas/tests/reductions/test_reductions.py

It showed that calling the following code:

s = Series([False, False, True, True, False, True], index=[0, 0, 1, 1, 2, 2])
s.any(bool_only=True)

would raise a NotImplementedError with the error message "Series.any does not implement numeric_only", and equivalent for calling s.all the same way. This error message is confusing because the user didn't pass numeric_only, they passed bool_only.

So the messages need to change to "Series.any does not implement bool_only" and "Series.all does not implement bool_only".

what actually needs to happen is we pass bool_only thru, but this increases the scope of this PR greatly.
-- @jreback #38720

@jreback jreback added Apply Apply, Aggregate, Transform, Map Error Reporting Incorrect or improved errors from pandas labels Dec 30, 2020
@jreback jreback added this to the Contributions Welcome milestone Dec 30, 2020
@theodorju
Copy link
Contributor

Hi, I'd like to work on this one since there is no one assigned.
Should only the string be changed, or the method's argument as well from numeric_only to boolean_only?

I'm referring to method _reduce on series.py.

@mroeschke mroeschke added Bug Reduction Operations sum, mean, min, max, etc. and removed Apply Apply, Aggregate, Transform, Map labels Aug 14, 2021
@weikhor
Copy link
Contributor

weikhor commented Apr 28, 2022

Pandas version I used:

1.5.0.dev0+725.g9f24918759

With this pandas version, the result is worked as expected.

  1. s = Series([False, False, True, True, False, True], index=[0, 0, 1, 1, 2, 2])
    s.all(bool_only=True)
    
    NotImplementedError: Series.all does not implement bool_only.
    
  2. s = Series([False, False, True, True, False, True], index=[0, 0, 1, 1, 2, 2])
    s.any(bool_only=True)
    
    NotImplementedError: Series.any does not implement bool_only.
    

@rhshadrach
Copy link
Member

Thanks @weikhor; this is tested for in test_all_any_params. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Error Reporting Incorrect or improved errors from pandas Reduction Operations sum, mean, min, max, etc.
Projects
None yet
Development

No branches or pull requests

6 participants