-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
BUG: raise when sort_index with ascending=None #39451
Conversation
971b3a9
to
7717f8b
Compare
pandas/util/_validators.py
Outdated
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Added
pandas/util/_validators.py
Outdated
Name of the argument. To be reflected in the error message. | ||
none_allowed : bool, optional | ||
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Added
pandas/core/generic.py
Outdated
@@ -11772,3 +11774,12 @@ def _doc_params(cls): | |||
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. | |||
""" | |||
|
|||
|
|||
def validate_ascending(ascending): |
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.
return [validate_bool_kwarg(item, "ascending", **kwargs) for item in ascending]
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 for ascending
.
pandas/core/generic.py
Outdated
@@ -11772,3 +11774,12 @@ def _doc_params(cls): | |||
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. | |||
""" | |||
|
|||
|
|||
def validate_ascending(ascending): |
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
can you merge master and fixup to comments. |
(True, None), | ||
(False, "True"), |
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 make these lists
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.
and maybe add an empty list too
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.
Currently an empty list does not raise an error, so the test fails.
Should I change the code, so that an empty list raises?
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.
@ivanovmg can you resolve conflicts and address comments
6559b4c
to
860c8a5
Compare
ok looks fine. can you add a whtasnew note for 1.2.3 in regression section. merge master and ping on green. |
thanks @ivanovmg |
@meeseeksdev backport 1.2.x |
This comment has been minimized.
This comment has been minimized.
…40083) Co-authored-by: Maxim Ivanov <[email protected]>
Added validation of
ascending
forsort_index
methods.Proposed a solution to raise
ValueError
when either of the elements ofascending
turned out to beNone
.