-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Fix sort_values for empty by argument #40324
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
Conversation
dsaxton
commented
Mar 9, 2021
- closes BUG: df.sort_values(by=[]) fails with IndexError #40258
- tests added / passed
- Ensure all linting tests pass, see here for how to run them
- whatsnew entry
pandas/core/frame.py
Outdated
@@ -5833,6 +5833,8 @@ def sort_values( # type: ignore[override] | |||
indexer = nargsort( | |||
k, kind=kind, ascending=ascending, na_position=na_position, key=key | |||
) | |||
else: | |||
return self |
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.
return self.copy()
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.
Good call, updated
@@ -79,6 +79,10 @@ def test_sort_values(self): | |||
with pytest.raises(ValueError, match=msg): | |||
frame.sort_values(by=["A", "B"], axis=0, ascending=[True] * 5) | |||
|
|||
# https://github.com/pandas-dev/pandas/issues/40258 |
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 add a separate test. also assert that it is not the same frame.
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 a completely separate test
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.
we dont' normally want to mix error checking with other things
doc/source/whatsnew/v1.2.4.rst
Outdated
@@ -25,7 +25,7 @@ Fixed regressions | |||
Bug fixes | |||
~~~~~~~~~ | |||
|
|||
- | |||
- Fixed bug in :meth:`DataFrame.sort_values` raising an :class:`IndexError` for empty ``by`` (:issue:`40258`) |
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.
move to 1.3, this is an expansion not a regression.
@@ -79,6 +79,10 @@ def test_sort_values(self): | |||
with pytest.raises(ValueError, match=msg): | |||
frame.sort_values(by=["A", "B"], axis=0, ascending=[True] * 5) | |||
|
|||
# https://github.com/pandas-dev/pandas/issues/40258 |
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 a completely separate test
@@ -79,6 +79,10 @@ def test_sort_values(self): | |||
with pytest.raises(ValueError, match=msg): | |||
frame.sort_values(by=["A", "B"], axis=0, ascending=[True] * 5) | |||
|
|||
# https://github.com/pandas-dev/pandas/issues/40258 |
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.
we dont' normally want to mix error checking with other things
thanks @dsaxton |