Skip to content

Commit 0d48f36

Browse files
committed
make typing in pandas_stubs.core.strings.pyi strict, add UnknownSeries and UnknownIndex
1 parent 5f22e39 commit 0d48f36

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

pandas-stubs/_typing.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,9 @@ S2 = TypeVar(
576576
| list[str],
577577
)
578578

579+
UnknownSeries: TypeAlias = Series[Any]
580+
UnknownIndex: TypeAlias = Index[Any]
581+
579582
IndexingInt: TypeAlias = (
580583
int | np.int_ | np.integer | np.unsignedinteger | np.signedinteger | np.int8
581584
)

pandas-stubs/core/strings.pyi

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ from typing import (
1111
overload,
1212
)
1313

14-
import numpy as np
14+
import numpy.typing as npt
1515
import pandas as pd
1616
from pandas import (
1717
DataFrame,
@@ -21,9 +21,13 @@ from pandas import (
2121
)
2222
from pandas.core.base import NoNewAttributesMixin
2323

24+
from pandas._libs.tslibs.nattype import NaTType
2425
from pandas._typing import (
2526
JoinHow,
27+
Scalar,
2628
T,
29+
UnknownIndex,
30+
UnknownSeries,
2731
np_ndarray_bool,
2832
)
2933

@@ -58,7 +62,7 @@ class StringMethods(NoNewAttributesMixin, Generic[T, _TS, _TM, _TS2]):
5862
@overload
5963
def cat(
6064
self,
61-
others: Series | pd.Index | pd.DataFrame | np.ndarray | list[Any],
65+
others: UnknownIndex | pd.DataFrame | npt.NDArray[Any] | list[Any],
6266
sep: str = ...,
6367
na_rep: str | None = ...,
6468
join: JoinHow = ...,
@@ -106,10 +110,10 @@ class StringMethods(NoNewAttributesMixin, Generic[T, _TS, _TM, _TS2]):
106110
def join(self, sep: str) -> T: ...
107111
def contains(
108112
self,
109-
pat: str | re.Pattern,
113+
pat: str | re.Pattern[str],
110114
case: bool = ...,
111115
flags: int = ...,
112-
na=...,
116+
na: Scalar | NaTType | None = ...,
113117
regex: bool = ...,
114118
) -> Series[bool]: ...
115119
def match(
@@ -118,7 +122,7 @@ class StringMethods(NoNewAttributesMixin, Generic[T, _TS, _TM, _TS2]):
118122
def replace(
119123
self,
120124
pat: str,
121-
repl: str | Callable[[re.Match], str],
125+
repl: str | Callable[[re.Match[str]], str],
122126
n: int = ...,
123127
case: bool | None = ...,
124128
flags: int = ...,
@@ -160,7 +164,7 @@ class StringMethods(NoNewAttributesMixin, Generic[T, _TS, _TM, _TS2]):
160164
def count(self, pat: str, flags: int = ...) -> Series[int]: ...
161165
def startswith(self, pat: str | tuple[str, ...], na: Any = ...) -> Series[bool]: ...
162166
def endswith(self, pat: str | tuple[str, ...], na: Any = ...) -> Series[bool]: ...
163-
def findall(self, pat: str, flags: int = ...) -> Series: ...
167+
def findall(self, pat: str, flags: int = ...) -> UnknownSeries: ...
164168
@overload
165169
def extract(
166170
self, pat: str, flags: int = ..., *, expand: Literal[True] = ...

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,12 @@ show_error_context = false
201201
show_column_numbers = false
202202
show_error_codes = true
203203

204+
[[tool.mypy.overrides]]
205+
module = [
206+
"pandas-stubs.core.strings.*",
207+
]
208+
strict = true
209+
204210
[tool.pyright]
205211
typeCheckingMode = "strict"
206212
stubPath = "."

0 commit comments

Comments
 (0)