diff --git a/pandas-stubs/core/strings.pyi b/pandas-stubs/core/strings.pyi index a21074dad..2597bd258 100644 --- a/pandas-stubs/core/strings.pyi +++ b/pandas-stubs/core/strings.pyi @@ -96,7 +96,12 @@ class StringMethods(NoNewAttributesMixin, Generic[T, _TS]): def get(self, i: int) -> T: ... def join(self, sep: str) -> T: ... def contains( - self, pat: str, case: bool = ..., flags: int = ..., na=..., regex: bool = ... + self, + pat: str | re.Pattern, + case: bool = ..., + flags: int = ..., + na=..., + regex: bool = ..., ) -> Series[bool]: ... def match( self, pat: str, case: bool = ..., flags: int = ..., na: Any = ... diff --git a/tests/test_series.py b/tests/test_series.py index e68028cc4..bad97f5b1 100644 --- a/tests/test_series.py +++ b/tests/test_series.py @@ -1452,6 +1452,11 @@ def test_string_accessors(): check(assert_type(s.str.cat(sep="X"), str), str) check(assert_type(s.str.center(10), pd.Series), pd.Series) check(assert_type(s.str.contains("a"), "pd.Series[bool]"), pd.Series, np.bool_) + check( + assert_type(s.str.contains(re.compile(r"a")), "pd.Series[bool]"), + pd.Series, + np.bool_, + ) check(assert_type(s.str.count("pp"), "pd.Series[int]"), pd.Series, np.integer) check(assert_type(s.str.decode("utf-8"), pd.Series), pd.Series) check(assert_type(s.str.encode("latin-1"), pd.Series), pd.Series)