Skip to content

Commit 4e5e68c

Browse files
committed
feat: progressive philosophy
1 parent f10e990 commit 4e5e68c

30 files changed

+177
-231
lines changed

pandas-stubs/core/series.pyi

Lines changed: 41 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,8 +1638,6 @@ class Series(IndexOpsMixin[S1], NDFrame):
16381638
# just failed to generate these so I couldn't match
16391639
# them up.
16401640
@overload
1641-
def __add__(self: Series[Never], other: _str) -> Never: ...
1642-
@overload
16431641
def __add__(
16441642
self: Series[Never], other: complex | _ListLike | Index | Series
16451643
) -> Series: ...
@@ -1755,14 +1753,6 @@ class Series(IndexOpsMixin[S1], NDFrame):
17551753
@overload
17561754
def __add__(self: Series[Timedelta], other: Period) -> PeriodSeries: ...
17571755
@overload
1758-
def add(
1759-
self: Series[Never],
1760-
other: _str,
1761-
level: Level | None = None,
1762-
fill_value: float | None = None,
1763-
axis: int = 0,
1764-
) -> Never: ...
1765-
@overload
17661756
def add(
17671757
self: Series[Never],
17681758
other: complex | _ListLike | Index | Series,
@@ -1937,8 +1927,6 @@ class Series(IndexOpsMixin[S1], NDFrame):
19371927
axis: int = 0,
19381928
) -> PeriodSeries: ...
19391929
@overload
1940-
def __radd__(self: Series[Never], other: _str) -> Never: ...
1941-
@overload
19421930
def __radd__(
19431931
self: Series[Never], other: complex | _ListLike | Index | Series
19441932
) -> Series: ...
@@ -2042,14 +2030,6 @@ class Series(IndexOpsMixin[S1], NDFrame):
20422030
@overload
20432031
def __radd__(self: Series[Timedelta], other: Period) -> PeriodSeries: ...
20442032
@overload
2045-
def radd(
2046-
self: Series[Never],
2047-
other: _str,
2048-
level: Level | None = None,
2049-
fill_value: float | None = None,
2050-
axis: int = 0,
2051-
) -> Never: ...
2052-
@overload
20532033
def radd(
20542034
self: Series[Never],
20552035
other: complex | _ListLike | Index | Series,
@@ -2777,11 +2757,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
27772757
@overload
27782758
def __sub__(
27792759
self: Series[Never],
2780-
other: datetime | np.datetime64 | np_ndarray_dt | DatetimeIndex,
2781-
) -> Never: ...
2782-
@overload
2783-
def __sub__(
2784-
self: Series[Never], other: complex | NumListLike | Index | Series[T_COMPLEX]
2760+
other: complex | NumListLike | Index[T_COMPLEX] | Series[T_COMPLEX],
27852761
) -> Series: ...
27862762
@overload
27872763
def __sub__(self, other: Index[Never] | Series[Never]) -> Series: ... # type: ignore[overload-overlap]
@@ -2904,28 +2880,10 @@ class Series(IndexOpsMixin[S1], NDFrame):
29042880
| TimedeltaSeries
29052881
),
29062882
) -> TimedeltaSeries: ...
2907-
# @overload
2908-
# def sub( # type: ignore[overload-overlap]
2909-
# self: Series[Never],
2910-
# other: Series[Never],
2911-
# level: Level | None = None,
2912-
# fill_value: float | None = None,
2913-
# axis: int = 0,
2914-
# ) -> Series: ...
29152883
@overload
29162884
def sub(
29172885
self: Series[Never],
2918-
other: (
2919-
DatetimeIndex | datetime | np.datetime64 | np_ndarray_dt
2920-
), # | Series[Timestamp],
2921-
level: Level | None = None,
2922-
fill_value: float | None = None,
2923-
axis: int = 0,
2924-
) -> Never: ...
2925-
@overload
2926-
def sub(
2927-
self: Series[Never],
2928-
other: complex | NumListLike | Index | Series,
2886+
other: complex | NumListLike | Index[T_COMPLEX] | Series[T_COMPLEX],
29292887
level: Level | None = None,
29302888
fill_value: float | None = None,
29312889
axis: int = 0,
@@ -3093,13 +3051,15 @@ class Series(IndexOpsMixin[S1], NDFrame):
30933051
axis: int = 0,
30943052
) -> TimedeltaSeries: ...
30953053
@overload
3096-
def __rsub__( # type: ignore[misc]
3097-
self: Series[Never],
3098-
other: datetime | np.datetime64 | np_ndarray_dt | DatetimeIndex,
3099-
) -> Never: ...
3100-
@overload
31013054
def __rsub__(
3102-
self: Series[Never], other: complex | NumListLike | Index | Series
3055+
self: Series[Never],
3056+
other: (
3057+
complex
3058+
| NumListLike
3059+
| Index[T_COMPLEX]
3060+
| Series[T_COMPLEX]
3061+
| Series[Timestamp]
3062+
),
31033063
) -> Series: ...
31043064
@overload
31053065
def __rsub__(self, other: Index[Never] | Series[Never]) -> Series: ...
@@ -3191,32 +3151,30 @@ class Series(IndexOpsMixin[S1], NDFrame):
31913151
| Series[complex]
31923152
),
31933153
) -> Series[complex]: ...
3194-
@overload
3195-
def __rsub__(self: Series[Timestamp], other: np_ndarray_td) -> Never: ...
3154+
# @overload
3155+
# def __rsub__(self: Series[Timestamp], other: np_ndarray_td) -> Never: ...
31963156
@overload
31973157
def __rsub__(
31983158
self: Series[Timestamp], other: datetime | np.datetime64 | np_ndarray_dt
31993159
) -> TimedeltaSeries: ...
32003160
@overload
3201-
def rsub(
3202-
self: Series[Never],
3203-
other: Series[Never],
3204-
level: Level | None = None,
3205-
fill_value: float | None = None,
3206-
axis: int = 0,
3207-
) -> Series: ...
3161+
def __rsub__(
3162+
self: Series[Timestamp], other: Series[Timestamp]
3163+
) -> Series[Timedelta]: ...
32083164
@overload
3209-
def rsub(
3210-
self: Series[Never],
3211-
other: datetime | np.datetime64 | np_ndarray_dt | DatetimeIndex,
3212-
level: Level | None = None,
3213-
fill_value: float | None = None,
3214-
axis: int = 0,
3215-
) -> Never: ...
3165+
def __rsub__(
3166+
self: Series[Timedelta], other: Series[Timestamp]
3167+
) -> Series[Timestamp]: ...
32163168
@overload
32173169
def rsub(
32183170
self: Series[Never],
3219-
other: complex | NumListLike | Index | Series,
3171+
other: (
3172+
complex
3173+
| NumListLike
3174+
| Index[T_COMPLEX]
3175+
| Series[T_COMPLEX]
3176+
| Series[Timestamp]
3177+
),
32203178
level: Level | None = None,
32213179
fill_value: float | None = None,
32223180
axis: int = 0,
@@ -3338,6 +3296,14 @@ class Series(IndexOpsMixin[S1], NDFrame):
33383296
fill_value: float | None = None,
33393297
axis: int = 0,
33403298
) -> Series[complex]: ...
3299+
# @overload
3300+
# def rsub(
3301+
# self: Series[Timestamp],
3302+
# other: np_ndarray_td,
3303+
# level: Level | None = None,
3304+
# fill_value: float | None = None,
3305+
# axis: int = 0,
3306+
# ) -> Never: ...
33413307
@overload
33423308
def rsub(
33433309
self: Series[Timestamp],
@@ -3355,6 +3321,14 @@ class Series(IndexOpsMixin[S1], NDFrame):
33553321
axis: int = 0,
33563322
) -> Series[Timedelta]: ...
33573323
@overload
3324+
def rsub(
3325+
self: Series[Timedelta],
3326+
other: Series[Timestamp],
3327+
level: Level | None = None,
3328+
fill_value: float | None = None,
3329+
axis: int = 0,
3330+
) -> Series[Timestamp]: ...
3331+
@overload
33583332
def __truediv__( # type:ignore[overload-overlap]
33593333
self: Series[Never], other: complex | NumListLike | Series
33603334
) -> Series: ...

tests/indexes/arithmetic/bool/test_add.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def test_add_numpy_array() -> None:
5454

5555
# `numpy` typing gives the corresponding `ndarray`s in the static type
5656
# checking, where our `__radd__` cannot override. At runtime, they return
57-
# `Index`s with the correct element type.
57+
# `Index`s.
5858
check(assert_type(b + left, "npt.NDArray[np.bool_]"), pd.Index, np.bool_)
5959
check(assert_type(i + left, "npt.NDArray[np.int64]"), pd.Index, np.integer)
6060
check(assert_type(f + left, "npt.NDArray[np.float64]"), pd.Index, np.floating)

tests/indexes/arithmetic/complex/test_add.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def test_add_numpy_array() -> None:
5353

5454
# `numpy` typing gives the corresponding `ndarray`s in the static type
5555
# checking, where our `__radd__` cannot override. At runtime, they return
56-
# `Index`s with the correct element type.
56+
# `Index`s.
5757
check(assert_type(b + left, "npt.NDArray[np.bool_]"), pd.Index, np.complexfloating)
5858
check(assert_type(i + left, "npt.NDArray[np.int64]"), pd.Index, np.complexfloating)
5959
check(

tests/indexes/arithmetic/float/test_add.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def test_add_numpy_array() -> None:
5353

5454
# `numpy` typing gives the corresponding `ndarray`s in the static type
5555
# checking, where our `__radd__` cannot override. At runtime, they return
56-
# `Index`s with the correct element type.
56+
# `Index`s.
5757
check(assert_type(b + left, "npt.NDArray[np.bool_]"), pd.Index, np.floating)
5858
check(assert_type(i + left, "npt.NDArray[np.int64]"), pd.Index, np.floating)
5959
check(assert_type(f + left, "npt.NDArray[np.float64]"), pd.Index, np.floating)

tests/indexes/arithmetic/int/test_add.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def test_add_numpy_array() -> None:
5353

5454
# `numpy` typing gives the corresponding `ndarray`s in the static type
5555
# checking, where our `__radd__` cannot override. At runtime, they return
56-
# `Index`s with the correct element type.
56+
# `Series`.
5757
check(assert_type(b + left, "npt.NDArray[np.bool_]"), pd.Index, np.integer)
5858
check(assert_type(i + left, "npt.NDArray[np.int64]"), pd.Index, np.integer)
5959
check(assert_type(f + left, "npt.NDArray[np.float64]"), pd.Index, np.floating)

tests/indexes/arithmetic/test_add.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from typing import Any
2+
13
import numpy as np
2-
from numpy import typing as npt # noqa: F401
34
import pandas as pd
45
from typing_extensions import (
56
Never,
@@ -61,18 +62,22 @@ def test_add_i_numpy_array() -> None:
6162
# `numpy` typing gives the corresponding `ndarray`s in the static type
6263
# checking, where our `__radd__` cannot override. At runtime, they return
6364
# `Index`s.
64-
# `mypy` thinks the return types are `Any`, which is a bug.
65+
# microsoft/pyright#10924
6566
check(
66-
assert_type(b + left_i, "npt.NDArray[np.bool_]"), pd.Index # type: ignore[assert-type]
67+
assert_type(b + left_i, Any), # pyright: ignore[reportAssertTypeFailure]
68+
pd.Index,
6769
)
6870
check(
69-
assert_type(i + left_i, "npt.NDArray[np.int64]"), pd.Index # type: ignore[assert-type]
71+
assert_type(i + left_i, Any), # pyright: ignore[reportAssertTypeFailure]
72+
pd.Index,
7073
)
7174
check(
72-
assert_type(f + left_i, "npt.NDArray[np.float64]"), pd.Index # type: ignore[assert-type]
75+
assert_type(f + left_i, Any), # pyright: ignore[reportAssertTypeFailure]
76+
pd.Index,
7377
)
7478
check(
75-
assert_type(c + left_i, "npt.NDArray[np.complex128]"), pd.Index # type: ignore[assert-type]
79+
assert_type(c + left_i, Any), # pyright: ignore[reportAssertTypeFailure]
80+
pd.Index,
7681
)
7782

7883

tests/indexes/arithmetic/test_sub.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def test_sub_i_numpy_array() -> None:
5959
# `numpy` typing gives the corresponding `ndarray`s in the static type
6060
# checking, where our `__rsub__` cannot override. At runtime, they return
6161
# `Index`s.
62-
# `mypy` thinks the return types are `Any`, which is a bug.
62+
# microsoft/pyright#10924
6363
check(assert_type(b - left_i, NoReturn), pd.Index) # type: ignore[assert-type]
6464
check(
6565
assert_type(i - left_i, "npt.NDArray[np.int64]"), pd.Index # type: ignore[assert-type]

tests/series/arithmetic/bool/test_add.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def test_add_numpy_array() -> None:
7676

7777
# `numpy` typing gives the corresponding `ndarray`s in the static type
7878
# checking, where our `__radd__` cannot override. At runtime, they return
79-
# `Series`s with the correct element type.
79+
# `Series` with the correct element type.
8080
check(assert_type(b + left, "npt.NDArray[np.bool_]"), pd.Series, np.bool_)
8181
check(assert_type(i + left, "npt.NDArray[np.int64]"), pd.Series, np.integer)
8282
check(assert_type(f + left, "npt.NDArray[np.float64]"), pd.Series, np.floating)

tests/series/arithmetic/bool/test_mul.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def test_mul_numpy_array() -> None:
7676

7777
# `numpy` typing gives the corresponding `ndarray`s in the static type
7878
# checking, where our `__rmul__` cannot override. At runtime, they return
79-
# `Series`s with the correct element type.
79+
# `Series` with the correct element type.
8080
check(assert_type(b * left, "npt.NDArray[np.bool_]"), pd.Series, np.bool_)
8181
check(assert_type(i * left, "npt.NDArray[np.int64]"), pd.Series, np.integer)
8282
check(assert_type(f * left, "npt.NDArray[np.float64]"), pd.Series, np.floating)

tests/series/arithmetic/bool/test_sub.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def test_sub_numpy_array() -> None:
9191

9292
# `numpy` typing gives the corresponding `ndarray`s in the static type
9393
# checking, where our `__rsub__` cannot override. At runtime, they return
94-
# `Series`s with the correct element type.
94+
# `Series` with the correct element type.
9595
if TYPE_CHECKING_INVALID_USAGE:
9696
assert_type(b - left, Never)
9797
check(assert_type(i - left, "npt.NDArray[np.int64]"), pd.Series, np.integer)

0 commit comments

Comments
 (0)