Skip to content

Commit 9c58445

Browse files
committed
feat: #983 new TypeVar, following #990 (comment)
1 parent 2eafd54 commit 9c58445

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

pandas-stubs/core/indexes/base.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ from typing import (
1818
)
1919

2020
import numpy as np
21+
from numpy import typing as npt
2122
from pandas import (
2223
DataFrame,
2324
DatetimeIndex,
@@ -260,7 +261,7 @@ class Index(IndexOpsMixin[S1]):
260261
**kwargs,
261262
) -> Self: ...
262263
@property
263-
def str(self) -> StringMethods[Self, MultiIndex]: ...
264+
def str(self) -> StringMethods[Self, MultiIndex, npt.NDArray[np.bool_]]: ...
264265
def is_(self, other) -> bool: ...
265266
def __len__(self) -> int: ...
266267
def __array__(self, dtype=...) -> np.ndarray: ...

pandas-stubs/core/series.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
11631163
) -> Series[S1]: ...
11641164
def to_period(self, freq: _str | None = ..., copy: _bool = ...) -> DataFrame: ...
11651165
@property
1166-
def str(self) -> StringMethods[Series, DataFrame]: ...
1166+
def str(self) -> StringMethods[Series, DataFrame, Series[bool]]: ...
11671167
@property
11681168
def dt(self) -> CombinedDatetimelikeProperties: ...
11691169
@property

pandas-stubs/core/strings.pyi

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ from typing import (
1212
)
1313

1414
import numpy as np
15+
from numpy import typing as npt
1516
import pandas as pd
1617
from pandas import (
1718
DataFrame,
@@ -27,8 +28,10 @@ from pandas._typing import (
2728

2829
# The _TS type is what is used for the result of str.split with expand=True
2930
_TS = TypeVar("_TS", DataFrame, MultiIndex)
31+
# The _TM type is what is used for the result of str.match
32+
_TM = TypeVar("_TM", Series[bool], npt.NDArray[np.bool_])
3033

31-
class StringMethods(NoNewAttributesMixin, Generic[T, _TS]):
34+
class StringMethods(NoNewAttributesMixin, Generic[T, _TS, _TM]):
3235
def __init__(self, data: T) -> None: ...
3336
def __getitem__(self, key: slice | int) -> T: ...
3437
def __iter__(self) -> T: ...
@@ -100,7 +103,7 @@ class StringMethods(NoNewAttributesMixin, Generic[T, _TS]):
100103
) -> Series[bool]: ...
101104
def match(
102105
self, pat: str, case: bool = ..., flags: int = ..., na: Any = ...
103-
) -> Series[bool]: ...
106+
) -> _TM: ...
104107
def replace(
105108
self,
106109
pat: str,

0 commit comments

Comments
 (0)