Skip to content

Commit 6689722

Browse files
committed
test(str): create test for non named group
1 parent fdac1a3 commit 6689722

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pandas/tests/strings/test_find_replace.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,20 @@ def test_replace_named_groups_regex_swap_expected_fail(
639639
ser.str.replace(pattern, repl, regex=True)
640640

641641

642+
@pytest.mark.parametrize("use_compile", [True, False])
643+
def test_replace_non_named_group(any_string_dtype, use_compile):
644+
ser = Series(["var.one[0]", "var.two[1]", "var.three[2]"], dtype=any_string_dtype)
645+
pattern = r"\[(\d+)\]"
646+
if use_compile:
647+
pattern = re.compile(pattern)
648+
repl = r"(\1)"
649+
result = ser.str.replace(pattern, repl, regex=True)
650+
expected = Series(
651+
["var.one(0)", "var.two(1)", "var.three(2)"], dtype=any_string_dtype
652+
)
653+
tm.assert_series_equal(result, expected)
654+
655+
642656
def test_replace_callable_named_groups(any_string_dtype):
643657
# test regex named groups
644658
ser = Series(["Foo Bar Baz", np.nan], dtype=any_string_dtype)

0 commit comments

Comments
 (0)