-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: raise when sort_index with ascending=None #39451
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
Changes from 1 commit
4f34ed1
8e40cac
513e0c5
dd2d191
f06d5f4
4b8da49
8363293
29dd29a
25b4119
6a422b2
860c8a5
a51a343
e0ebf58
6b430f8
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 |
---|---|---|
|
@@ -205,9 +205,39 @@ def validate_args_and_kwargs(fname, args, kwargs, max_fname_arg_count, compat_ar | |
validate_kwargs(fname, kwargs, compat_args) | ||
|
||
|
||
def validate_bool_kwarg(value, arg_name): | ||
""" Ensures that argument passed in arg_name is of type bool. """ | ||
if not (is_bool(value) or value is None): | ||
def validate_bool_kwarg(value, arg_name, none_allowed=True, int_allowed=False): | ||
simonjayhawkins marked this conversation as resolved.
Show resolved
Hide resolved
jreback marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
Ensure that argument passed in arg_name can be interpreted as boolean. | ||
|
||
Parameters | ||
---------- | ||
value : bool | ||
Value to be validated. | ||
arg_name : str | ||
Name of the argument. To be reflected in the error message. | ||
none_allowed : bool, optional | ||
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. add default 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. Added |
||
Whether to consider None to be a valid boolean. | ||
int_allowed : bool, optional | ||
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. same 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. Added |
||
Whether to consider integer value to be a valid boolean. | ||
|
||
Returns | ||
------- | ||
value | ||
The same value as input. | ||
|
||
Raises | ||
------ | ||
ValueError | ||
If the value is not a valid boolean. | ||
""" | ||
good_value = is_bool(value) | ||
if none_allowed: | ||
good_value = good_value or value is None | ||
|
||
if int_allowed: | ||
good_value = good_value or isinstance(value, int) | ||
|
||
if not good_value: | ||
raise ValueError( | ||
f'For argument "{arg_name}" expected type bool, received ' | ||
f"type {type(value).__name__}." | ||
|
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.
can you move to pandas/util/validators.py
shouldn't this raise for a list-like case if something is wrong?
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.
e.g. this shouldn't return anything
pls add some typing
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.
It raises for a list-like case if any of the items in
ascending
list is not treated as a valid boolean.This construct does just that.
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 can simply be part of validate_bool_kwarg or another function but should be co-located with validate_bool_kwarg
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.
Moved the function to
pandas/util/_validators.py
.It is not clear for me at the moment how to make this validation anyhow different (as a part of
validate_bool_kwarg
) due to the fact that multiple types are acceptable forascending
.