-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
Fixed bug: Dataframe.sort_values not raising ValueError for ascending-incompatible value and Series.sort_values raising ValueError for int value #42684
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 3 commits
3677a9e
a84e1c0
f50c032
0ed2a01
74ee732
9548857
9d394ec
145defd
e5cc3ae
1170905
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 |
---|---|---|
|
@@ -51,7 +51,7 @@ def test_sort_values(self, datetime_series): | |
expected = ts.sort_values(ascending=False, na_position="first") | ||
tm.assert_series_equal(expected, ordered) | ||
|
||
msg = "ascending must be boolean" | ||
msg = 'For argument "ascending" expected type bool, received type NoneType.' | ||
with pytest.raises(ValueError, match=msg): | ||
ts.sort_values(ascending=None) | ||
msg = r"Length of ascending \(0\) must be 1 for Series" | ||
|
@@ -63,7 +63,7 @@ def test_sort_values(self, datetime_series): | |
msg = r"Length of ascending \(2\) must be 1 for Series" | ||
with pytest.raises(ValueError, match=msg): | ||
ts.sort_values(ascending=[False, False]) | ||
msg = "ascending must be boolean" | ||
msg = 'For argument "ascending" expected type bool, received type str.' | ||
with pytest.raises(ValueError, match=msg): | ||
ts.sort_values(ascending="foobar") | ||
|
||
|
@@ -206,6 +206,25 @@ def test_mergesort_decending_stability(self): | |
expected = Series([3, 2, 1, 1], ["c", "b", "first", "second"]) | ||
tm.assert_series_equal(result, expected) | ||
|
||
def test_sort_values_validate_ascending(self): | ||
gaikwadrahul20 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# GH41634 | ||
ser = Series([23, 7, 21]) | ||
expected = np.sort(ser.values)[::-1] | ||
|
||
msg = 'For argument "ascending" expected type bool, received type str.' | ||
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. would it not be better to separate the raises ValueError test and the functional tests?
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. Thanks @attack68. I agree, code will look more clean and short. Pushed a change for this, please check. Also, I was thinking, does it make more sense to parameterize
|
||
with pytest.raises(ValueError, match=msg): | ||
ser.sort_values(ascending="False") | ||
|
||
sorted_ser = ser.sort_values(ascending=False) | ||
tm.assert_numpy_array_equal(sorted_ser.values, expected) | ||
|
||
sorted_ser = ser.sort_values(ascending=0) | ||
tm.assert_numpy_array_equal(sorted_ser.values, expected) | ||
|
||
expected = expected[::-1] | ||
sorted_ser = ser.sort_values(ascending=1) | ||
tm.assert_numpy_array_equal(sorted_ser.values, expected) | ||
|
||
|
||
class TestSeriesSortingKey: | ||
def test_sort_values_key(self): | ||
|
Uh oh!
There was an error while loading. Please reload this page.