-
-
Notifications
You must be signed in to change notification settings - Fork 19k
CLN: Enforce deprecation of not validating na argument to string methods #62399
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -22,6 +22,7 @@ | |||||
is_bool, | ||||||
is_integer, | ||||||
) | ||||||
from pandas.core.dtypes.missing import isna | ||||||
|
||||||
BoolishT = TypeVar("BoolishT", bool, int) | ||||||
BoolishNoneT = TypeVar("BoolishNoneT", bool, int, None) | ||||||
|
@@ -269,6 +270,37 @@ def validate_bool_kwarg( | |||||
return value | ||||||
|
||||||
|
||||||
def validate_na_arg( | ||||||
value, name: str, allow_no_default: bool = False, allow_bool: bool = False | ||||||
): | ||||||
""" | ||||||
Validate na arguments. | ||||||
|
||||||
Parameters | ||||||
---------- | ||||||
value : object | ||||||
Value to validate. | ||||||
name : str | ||||||
Name of the argument, used to raise an informative error message. | ||||||
allow_no_default : bool, default False | ||||||
Whether to allow ``value`` to be ``lib.no_default``. | ||||||
allow_bool : bool, default False | ||||||
Whether to allow ``value`` to be an instance of bool. | ||||||
|
||||||
Raises | ||||||
______ | ||||||
ValueError | ||||||
When ``value`` is determined to be invalid. | ||||||
""" | ||||||
if allow_no_default and value is lib.no_default: | ||||||
return | ||||||
if allow_bool and isinstance(value, bool): | ||||||
return | ||||||
if isna(value): | ||||||
return | ||||||
raise ValueError(f"{name} must be a valid NA value; got {value}") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW, I don't know if there is a case for which you are foreseeing (so for now could also simplify things leaving out the keywords?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How would you feel about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I personally think it is useful to give an indication about what a valid value is (or say "a valid value for dtype ..", so then if it is bool, then it is clearer that it should be True/False or a missing value (for nullable bool)?) |
||||||
|
||||||
|
||||||
def validate_fillna_kwargs(value, method, validate_scalar_dict_value: bool = True): | ||||||
""" | ||||||
Validate the keyword arguments to 'fillna'. | ||||||
|
Uh oh!
There was an error while loading. Please reload this page.