Skip to content

Commit 5c23f68

Browse files
Dr-Irvcmp0xff
authored andcommitted
handle str ops
1 parent e0b5b59 commit 5c23f68

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

pandas-stubs/core/series.pyi

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ class _LocIndexerSeries(_LocIndexer, Generic[S1]):
260260
value: S1 | ArrayLike | Series[S1] | None,
261261
) -> None: ...
262262

263-
_ListLike: TypeAlias = (
263+
_ListLike: TypeAlias = ArrayLike | dict[_str, np.ndarray] | SequenceNotStr[S1]
264+
_ListLikeS1: TypeAlias = (
264265
ArrayLike | dict[_str, np.ndarray] | Sequence[S1] | IndexOpsMixin[S1]
265266
)
266267
_NumListLike: TypeAlias = (
@@ -428,7 +429,9 @@ class Series(IndexOpsMixin[S1], NDFrame):
428429
@overload
429430
def __new__(
430431
cls,
431-
data: S1 | _ListLike[S1] | dict[HashableT1, S1] | KeysView[S1] | ValuesView[S1],
432+
data: (
433+
S1 | _ListLikeS1[S1] | dict[HashableT1, S1] | KeysView[S1] | ValuesView[S1]
434+
),
432435
index: AxesData | None = ...,
433436
dtype: Dtype = ...,
434437
name: Hashable = ...,
@@ -2060,7 +2063,9 @@ class Series(IndexOpsMixin[S1], NDFrame):
20602063
self, other: S1 | _ListLike | Series[S1] | datetime | timedelta | date
20612064
) -> Series[_bool]: ...
20622065
@overload
2063-
def __mul__(self: Series[Never], other: complex | _ListLike | Series) -> Series: ...
2066+
def __mul__(
2067+
self: Series[Never], other: complex | _NumListLike | Series
2068+
) -> Series: ...
20642069
@overload
20652070
def __mul__(self, other: Series[Never]) -> Series: ... # type: ignore[overload-overlap]
20662071
@overload
@@ -2255,7 +2260,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
22552260
) -> TimedeltaSeries: ...
22562261
@overload
22572262
def __rmul__(
2258-
self: Series[Never], other: complex | _ListLike | Series
2263+
self: Series[Never], other: complex | _NumListLike | Series
22592264
) -> Series: ...
22602265
@overload
22612266
def __rmul__(self, other: Series[Never]) -> Series: ... # type: ignore[overload-overlap]
@@ -2892,8 +2897,8 @@ class Series(IndexOpsMixin[S1], NDFrame):
28922897
axis: int = 0,
28932898
) -> Series[complex]: ...
28942899
@overload
2895-
def __truediv__(
2896-
self: Series[Never], other: complex | _ListLike | Series
2900+
def __truediv__( # type:ignore[overload-overlap]
2901+
self: Series[Never], other: complex | _NumListLike | Series
28972902
) -> Series: ...
28982903
@overload
28992904
def __truediv__(self, other: Series[Never]) -> Series: ...
@@ -3088,8 +3093,8 @@ class Series(IndexOpsMixin[S1], NDFrame):
30883093
) -> Series: ...
30893094
div = truediv
30903095
@overload
3091-
def __rtruediv__(
3092-
self: Series[Never], other: complex | _ListLike | Series
3096+
def __rtruediv__( # type:ignore[overload-overlap]
3097+
self: Series[Never], other: complex | _NumListLike | Series
30933098
) -> Series: ...
30943099
@overload
30953100
def __rtruediv__(self, other: Series[Never]) -> Series: ...

tests/series/arithmetic/test_sub.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,3 +242,13 @@ def test_sub_ts_pd_datetime_2() -> None:
242242
# When I merge this one to the previous one, mypy does not allow me to pass
243243
left_td.rsub(s) # type: ignore[arg-type] # pyright: ignore[reportArgumentType,reportCallIssue]
244244
assert_type(left_td.rsub(a), Never)
245+
246+
247+
def test_str_sub() -> None:
248+
if TYPE_CHECKING_INVALID_USAGE:
249+
left_i - "abc" # type: ignore[operator] # pyright:ignore[reportOperatorIssue]
250+
"abc" - left_i # type: ignore[operator] # pyright:ignore[reportOperatorIssue]
251+
left_i * "abc" # type: ignore[operator] # pyright:ignore[reportOperatorIssue]
252+
"abc" * left_i # type: ignore[operator] # pyright:ignore[reportOperatorIssue]
253+
left_i / "abc" # type: ignore[operator] # pyright:ignore[reportOperatorIssue]
254+
"abc" / left_i # type: ignore[operator] # pyright:ignore[reportOperatorIssue]

0 commit comments

Comments
 (0)