Skip to content

Commit 4f34ed1

Browse files
committed
TST: add failing tests
1 parent bdfaea4 commit 4f34ed1

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

pandas/tests/frame/methods/test_sort_index.py

+16
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,22 @@ def test_sort_index_with_categories(self, categories):
761761
)
762762
tm.assert_frame_equal(result, expected)
763763

764+
@pytest.mark.parametrize(
765+
"ascending",
766+
[
767+
None,
768+
(True, None),
769+
(False, 'True'),
770+
],
771+
)
772+
def test_sort_index_ascending_bad_value_raises(self, ascending):
773+
df = DataFrame(np.arange(64))
774+
length = len(df.index)
775+
df.index = [(i - length / 2) % length for i in range(length)]
776+
match = "ascending must be either a bool or a sequence of bools"
777+
with pytest.raises(ValueError, match=match):
778+
df.sort_index(axis=0, ascending=ascending, na_position="first")
779+
764780

765781
class TestDataFrameSortIndexKey:
766782
def test_sort_multi_index_key(self):

pandas/tests/series/methods/test_sort_index.py

+14
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,20 @@ def test_sort_index_ascending_list(self):
198198
expected = ser.iloc[[0, 4, 1, 5, 2, 6, 3, 7]]
199199
tm.assert_series_equal(result, expected)
200200

201+
@pytest.mark.parametrize(
202+
"ascending",
203+
[
204+
None,
205+
(True, None),
206+
(False, 'True'),
207+
],
208+
)
209+
def test_sort_index_ascending_bad_value_raises(self, ascending):
210+
ser = Series(range(10), index=[0, 3, 2, 1, 4, 5, 7, 6, 8, 9])
211+
match = "ascending must be either a bool or a sequence of bools"
212+
with pytest.raises(ValueError, match=match):
213+
ser.sort_index(ascending=ascending)
214+
201215

202216
class TestSeriesSortIndexKey:
203217
def test_sort_index_multiindex_key(self):

0 commit comments

Comments
 (0)