Skip to content

Commit b377a78

Browse files
simonjayhawkinsjreback
authored andcommitted
TST/CLN: remove try block from tests/test_strings.py::TestStringMethods::test_slice (#27277)
1 parent 4dc2b69 commit b377a78

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

pandas/tests/test_strings.py

+13-16
Original file line numberDiff line numberDiff line change
@@ -2795,23 +2795,20 @@ def test_pipe_failures(self):
27952795

27962796
tm.assert_series_equal(result, exp)
27972797

2798-
def test_slice(self):
2798+
@pytest.mark.parametrize(
2799+
"start, stop, step, expected",
2800+
[
2801+
(2, 5, None, Series(["foo", "bar", NA, "baz"])),
2802+
(0, 3, -1, Series(["", "", NA, ""])),
2803+
(None, None, -1, Series(["owtoofaa", "owtrabaa", NA, "xuqzabaa"])),
2804+
(3, 10, 2, Series(["oto", "ato", NA, "aqx"])),
2805+
(3, 0, -1, Series(["ofa", "aba", NA, "aba"])),
2806+
],
2807+
)
2808+
def test_slice(self, start, stop, step, expected):
27992809
values = Series(["aafootwo", "aabartwo", NA, "aabazqux"])
2800-
2801-
result = values.str.slice(2, 5)
2802-
exp = Series(["foo", "bar", NA, "baz"])
2803-
tm.assert_series_equal(result, exp)
2804-
2805-
for start, stop, step in [(0, 3, -1), (None, None, -1), (3, 10, 2), (3, 0, -1)]:
2806-
try:
2807-
result = values.str.slice(start, stop, step)
2808-
expected = Series(
2809-
[s[start:stop:step] if not isna(s) else NA for s in values]
2810-
)
2811-
tm.assert_series_equal(result, expected)
2812-
except IndexError:
2813-
print("failed on %s:%s:%s" % (start, stop, step))
2814-
raise
2810+
result = values.str.slice(start, stop, step)
2811+
tm.assert_series_equal(result, expected)
28152812

28162813
# mixed
28172814
mixed = Series(

0 commit comments

Comments
 (0)