| 60 | |
| 61 | |
| 62 | def test_split_regex_explicit(any_string_dtype): |
| 63 | # explicit regex = True split with compiled regex |
| 64 | regex_pat = re.compile(r".jpg") |
| 65 | values = Series("xxxjpgzzz.jpg", dtype=any_string_dtype) |
| 66 | result = values.str.split(regex_pat) |
| 67 | exp = Series([["xx", "zzz", ""]]) |
| 68 | tm.assert_series_equal(result, exp) |
| 69 | |
| 70 | # explicit regex = False split |
| 71 | result = values.str.split(r"\.jpg", regex=False) |
| 72 | exp = Series([["xxxjpgzzz.jpg"]]) |
| 73 | tm.assert_series_equal(result, exp) |
| 74 | |
| 75 | # non explicit regex split, pattern length == 1 |
| 76 | result = values.str.split(r".") |
| 77 | exp = Series([["xxxjpgzzz", "jpg"]]) |
| 78 | tm.assert_series_equal(result, exp) |
| 79 | |
| 80 | # non explicit regex split, pattern length != 1 |
| 81 | result = values.str.split(r".jpg") |
| 82 | exp = Series([["xx", "zzz", ""]]) |
| 83 | tm.assert_series_equal(result, exp) |
| 84 | |
| 85 | # regex=False with pattern compiled regex raises error |
| 86 | with pytest.raises( |
| 87 | ValueError, |
| 88 | match="Cannot use a compiled regex as replacement pattern with regex=False", |
| 89 | ): |
| 90 | values.str.split(regex_pat, regex=False) |
| 91 | |
| 92 | |
| 93 | @pytest.mark.parametrize("expand", [None, False]) |