-
-
Notifications
You must be signed in to change notification settings - Fork 19.4k
Fix/53098 numeric only disallow non bools #62632
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
base: main
Are you sure you want to change the base?
Fix/53098 numeric only disallow non bools #62632
Conversation
This reverts commit ecf23e1.
…ne during 2.x)\n\nAdds a centralized helper that emits a PandasFutureWarning for numeric_only=None to support a warn-first migration (GH#53098).
…recate_numeric_only_none and validate_bool_kwarg at central reduction entry points (DataFrame._reduce, Series._reduce, GroupBy._cython_agg_general, Rolling._validate_numeric_only). Emit PandasFutureWarning for numeric_only=None (GH#53098).
…numeric_only=None using tm.assert_produces_warning
|
I see some tests failing, which I couldn't catch locally. Any suggestion on what I am missing will be helpful. |
|
Some of them can be fixed if you merge from main. |
| # validate numeric_only is strictly a bool (disallow None, ints, etc.) | ||
| # Deprecate passing None to numeric_only: warn now, error in a future | ||
| # release. See GH#53098. | ||
| from pandas.util._validators import deprecate_numeric_only_none |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do this import at the top of the file
| # Note: we never get here with how="ohlc" for DataFrameGroupBy; | ||
| # that goes through SeriesGroupBy | ||
|
|
||
| # validate numeric_only is strictly a bool (disallow None, ints, etc.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this comment can go in the implementation of deprecate_numeric_only_none, is not needed at every place where it is called
| # New behavior: numeric_only=None is deprecated; emit a warning but | ||
| # continue to accept it during the deprecation period. | ||
| if numeric_only is None: | ||
| from pandas import errors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
top of the file, should probably be Pandas4Warning?
| return value | ||
|
|
||
|
|
||
| # deprecate_numeric_only_none defined later in file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed
| """ | ||
| import warnings | ||
|
|
||
| from pandas import errors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
top of the file
| f'Passing None for "{arg_name}" is deprecated and will raise a ' | ||
| "ValueError in a future version; please pass True or False." | ||
| ) | ||
| warnings.warn(msg, errors.PandasFutureWarning, stacklevel=2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use stacklevel=find_stack_level()
numeric_onlyin reduction operations should disallow passing non-bools #53098 (Replace xxxx with the GitHub issue number)doc/source/whatsnew/vX.X.X.rstfile if fixing a bug or adding a new feature.Ran tests:
Groupby tests: 29766 passed, 440 skipped, 45 xfailed, 39 xpassed, 1 warning.
Window tests (with Numba disabled to avoid an env crash): 9869 passed, 28 skipped, 91 xfailed.
Frame reductions tests: 2338 passed, 2 xfailed.
No real test failures (only xfails/skips) after applying the deprecation behavior.
Changes
Implemented the deprecation approach for numeric_only=None during the 2.x cycle:
frame.py : (DataFrame._reduce)
series.py : (Series._reduce)
groupby.py :(GroupBy._cython_agg_general)
rolling.py : (Rolling._validate_numeric_only)