Skip to content

Commit e59870a

Browse files
committed
Allow str.contains to accept a regex as well as a string
1 parent d2798db commit e59870a

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

pandas-stubs/core/strings.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class StringMethods(NoNewAttributesMixin, Generic[T, _TS]):
9696
def get(self, i: int) -> T: ...
9797
def join(self, sep: str) -> T: ...
9898
def contains(
99-
self, pat: str, case: bool = ..., flags: int = ..., na=..., regex: bool = ...
99+
self, pat: str | re.Pattern, case: bool = ..., flags: int = ..., na=..., regex: bool = ...
100100
) -> Series[bool]: ...
101101
def match(
102102
self, pat: str, case: bool = ..., flags: int = ..., na: Any = ...

tests/test_series.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,6 +1452,7 @@ def test_string_accessors():
14521452
check(assert_type(s.str.cat(sep="X"), str), str)
14531453
check(assert_type(s.str.center(10), pd.Series), pd.Series)
14541454
check(assert_type(s.str.contains("a"), "pd.Series[bool]"), pd.Series, np.bool_)
1455+
check(assert_type(s.str.contains(re.compile(r"a")), "pd.Series[bool]"), pd.Series, np.bool_)
14551456
check(assert_type(s.str.count("pp"), "pd.Series[int]"), pd.Series, np.integer)
14561457
check(assert_type(s.str.decode("utf-8"), pd.Series), pd.Series)
14571458
check(assert_type(s.str.encode("latin-1"), pd.Series), pd.Series)

0 commit comments

Comments
 (0)