Skip to content

Commit 2a2291b

Browse files
authored
Allow tuple[str, ...] pattern to be passed to str.startswith / str.endswith (#427)
1 parent db3b883 commit 2a2291b

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

pandas-stubs/core/strings.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ class StringMethods(NoNewAttributesMixin, Generic[T, _TS]):
142142
def get_dummies(self, sep: str = ...) -> pd.DataFrame: ...
143143
def translate(self, table: dict[int, int | str | None] | None) -> T: ...
144144
def count(self, pat: str, flags: int = ...) -> Series[int]: ...
145-
def startswith(self, pat: str, na: Any = ...) -> Series[bool]: ...
146-
def endswith(self, pat: str, na: Any = ...) -> Series[bool]: ...
145+
def startswith(self, pat: str | tuple[str, ...], na: Any = ...) -> Series[bool]: ...
146+
def endswith(self, pat: str | tuple[str, ...], na: Any = ...) -> Series[bool]: ...
147147
def findall(self, pat: str, flags: int = ...) -> Series: ...
148148
@overload
149149
def extract(

tests/test_series.py

+6
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,7 @@ def test_string_accessors():
995995
check(assert_type(s.str.decode("utf-8"), pd.Series), pd.Series)
996996
check(assert_type(s.str.encode("latin-1"), pd.Series), pd.Series)
997997
check(assert_type(s.str.endswith("e"), "pd.Series[bool]"), pd.Series, bool)
998+
check(assert_type(s.str.endswith(("e", "f")), "pd.Series[bool]"), pd.Series, bool)
998999
check(assert_type(s3.str.extract(r"([ab])?(\d)"), pd.DataFrame), pd.DataFrame)
9991000
check(assert_type(s3.str.extractall(r"([ab])?(\d)"), pd.DataFrame), pd.DataFrame)
10001001
check(assert_type(s.str.find("p"), pd.Series), pd.Series)
@@ -1038,6 +1039,11 @@ def test_string_accessors():
10381039
# GH 194
10391040
check(assert_type(s.str.split("a", expand=True), pd.DataFrame), pd.DataFrame)
10401041
check(assert_type(s.str.startswith("a"), "pd.Series[bool]"), pd.Series, bool)
1042+
check(
1043+
assert_type(s.str.startswith(("a", "b")), "pd.Series[bool]"),
1044+
pd.Series,
1045+
bool,
1046+
)
10411047
check(assert_type(s.str.strip(), pd.Series), pd.Series)
10421048
check(assert_type(s.str.swapcase(), pd.Series), pd.Series)
10431049
check(assert_type(s.str.title(), pd.Series), pd.Series)

0 commit comments

Comments
 (0)