-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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 all 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,27 @@ 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_for_value_error(self): | ||
# GH41634 | ||
ser = Series([23, 7, 21]) | ||
|
||
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") | ||
|
||
@pytest.mark.parametrize("ascending", [False, 0, 1, True]) | ||
def test_sort_values_validate_ascending_functional(self, ascending): | ||
# GH41634 | ||
ser = Series([23, 7, 21]) | ||
expected = np.sort(ser.values) | ||
|
||
sorted_ser = ser.sort_values(ascending=ascending) | ||
if not ascending: | ||
expected = expected[::-1] | ||
|
||
result = sorted_ser.values | ||
tm.assert_numpy_array_equal(result, expected) | ||
|
||
|
||
class TestSeriesSortingKey: | ||
def test_sort_values_key(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.
this is an extraneous note (the 2nd) that likley came in during rebase
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.
@jreback I think this is also taken care by you.