Skip to content

Commit 4245375

Browse files
committed
fix(comment): #1314 (comment)
1 parent bce1979 commit 4245375

File tree

2 files changed

+65
-48
lines changed

2 files changed

+65
-48
lines changed

pandas-stubs/core/series.pyi

Lines changed: 61 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ from pandas.core.dtypes.dtypes import CategoricalDtype
188188

189189
from pandas.plotting import PlotAccessor
190190

191-
_T_NUM_NON_BOOL = TypeVar("_T_NUM_NON_BOOL", int, float, complex)
192191
_T_INT = TypeVar("_T_INT", bound=int)
193192
_T_COMPLEX = TypeVar("_T_COMPLEX", bound=complex)
194193

@@ -2124,8 +2123,8 @@ class Series(IndexOpsMixin[S1], NDFrame):
21242123
def __truediv__(
21252124
self: Series[int],
21262125
other: (
2127-
_T_INT
2128-
| Sequence[_T_INT]
2126+
int
2127+
| Sequence[int]
21292128
| np_ndarray_bool
21302129
| np_ndarray_anyint
21312130
| np_ndarray_float
@@ -2141,8 +2140,8 @@ class Series(IndexOpsMixin[S1], NDFrame):
21412140
def __truediv__(
21422141
self: Series[float],
21432142
other: (
2144-
_T_INT
2145-
| Sequence[_T_INT]
2143+
int
2144+
| Sequence[int]
21462145
| np_ndarray_bool
21472146
| np_ndarray_anyint
21482147
| np_ndarray_float
@@ -2155,10 +2154,6 @@ class Series(IndexOpsMixin[S1], NDFrame):
21552154
other: _T_COMPLEX | Sequence[_T_COMPLEX] | Series[_T_COMPLEX],
21562155
) -> Series[_T_COMPLEX]: ...
21572156
@overload
2158-
def __truediv__(
2159-
self: Series[_T_COMPLEX], other: np_ndarray_complex
2160-
) -> Series[complex]: ...
2161-
@overload
21622157
def __truediv__(
21632158
self: Series[complex],
21642159
other: (
@@ -2171,6 +2166,10 @@ class Series(IndexOpsMixin[S1], NDFrame):
21712166
),
21722167
) -> Series[complex]: ...
21732168
@overload
2169+
def __truediv__(
2170+
self: Series[_T_COMPLEX], other: np_ndarray_complex
2171+
) -> Series[complex]: ...
2172+
@overload
21742173
def __truediv__(self, other: Path) -> Series: ...
21752174
@overload
21762175
def truediv(
@@ -2181,7 +2180,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
21812180
axis: AxisIndex = 0,
21822181
) -> Series: ...
21832182
@overload
2184-
def truediv( # type: ignore[overload-overlap]
2183+
def truediv(
21852184
self,
21862185
other: Series[Never],
21872186
level: Level | None = None,
@@ -2191,33 +2190,40 @@ class Series(IndexOpsMixin[S1], NDFrame):
21912190
@overload
21922191
def truediv(
21932192
self: Series[bool],
2194-
other: bool | np_ndarray_bool | Series[bool],
2193+
other: bool | np_ndarray_bool,
21952194
level: Level | None = None,
21962195
fill_value: float | None = None,
21972196
axis: AxisIndex = 0,
21982197
) -> Never: ...
21992198
@overload
2200-
def truediv(
2199+
def truediv( # pyright: ignore[reportOverlappingOverload]
22012200
self: Series[bool],
2202-
other: int | Sequence[int] | np_ndarray_anyint | np_ndarray_float | Series[int],
2201+
other: (
2202+
float
2203+
| Sequence[float]
2204+
| np_ndarray_anyint
2205+
| np_ndarray_float
2206+
| Series[int]
2207+
| Series[float]
2208+
),
22032209
level: Level | None = None,
22042210
fill_value: float | None = None,
22052211
axis: AxisIndex = 0,
22062212
) -> Series[float]: ...
22072213
@overload
2208-
def truediv( # type: ignore[overload-overlap]
2214+
def truediv(
22092215
self: Series[bool],
2210-
other: _T_NUM_NON_BOOL | Sequence[_T_NUM_NON_BOOL] | Series[_T_NUM_NON_BOOL],
2216+
other: complex | Sequence[complex] | Series[complex],
22112217
level: Level | None = None,
22122218
fill_value: float | None = None,
22132219
axis: AxisIndex = 0,
2214-
) -> Series[_T_NUM_NON_BOOL]: ...
2220+
) -> Series[complex]: ...
22152221
@overload
22162222
def truediv(
22172223
self: Series[int],
22182224
other: (
2219-
_T_INT
2220-
| Sequence[_T_INT]
2225+
int
2226+
| Sequence[int]
22212227
| np_ndarray_bool
22222228
| np_ndarray_anyint
22232229
| np_ndarray_float
@@ -2259,14 +2265,6 @@ class Series(IndexOpsMixin[S1], NDFrame):
22592265
axis: AxisIndex = 0,
22602266
) -> Series[_T_COMPLEX]: ...
22612267
@overload
2262-
def truediv(
2263-
self: Series[_T_COMPLEX],
2264-
other: np_ndarray_complex,
2265-
level: Level | None = None,
2266-
fill_value: float | None = None,
2267-
axis: AxisIndex = 0,
2268-
) -> Series[complex]: ...
2269-
@overload
22702268
def truediv(
22712269
self: Series[complex],
22722270
other: (
@@ -2282,6 +2280,14 @@ class Series(IndexOpsMixin[S1], NDFrame):
22822280
axis: AxisIndex = 0,
22832281
) -> Series[complex]: ...
22842282
@overload
2283+
def truediv(
2284+
self: Series[_T_COMPLEX],
2285+
other: np_ndarray_complex,
2286+
level: Level | None = None,
2287+
fill_value: float | None = None,
2288+
axis: AxisIndex = 0,
2289+
) -> Series[complex]: ...
2290+
@overload
22852291
def truediv(
22862292
self,
22872293
other: Path,
@@ -2295,23 +2301,19 @@ class Series(IndexOpsMixin[S1], NDFrame):
22952301
@overload
22962302
def __rtruediv__(self: Series[bool], other: bool | np_ndarray_bool) -> Never: ...
22972303
@overload
2298-
def __rtruediv__(
2304+
def __rtruediv__( # pyright: ignore[reportOverlappingOverload]
22992305
self: Series[bool],
2300-
other: int | Sequence[int] | np_ndarray_anyint | np_ndarray_float,
2306+
other: float | Sequence[float] | np_ndarray_anyint | np_ndarray_float,
23012307
) -> Series[float]: ...
23022308
@overload
2303-
def __rtruediv__( # type: ignore[overload-overlap]
2304-
self: Series[bool], other: _T_NUM_NON_BOOL | Sequence[_T_NUM_NON_BOOL]
2305-
) -> Series[_T_NUM_NON_BOOL]: ...
2309+
def __rtruediv__(
2310+
self: Series[bool], other: complex | Sequence[complex]
2311+
) -> Series[complex]: ...
23062312
@overload
23072313
def __rtruediv__(
23082314
self: Series[int],
23092315
other: (
2310-
_T_INT
2311-
| Sequence[_T_INT]
2312-
| np_ndarray_bool
2313-
| np_ndarray_anyint
2314-
| np_ndarray_float
2316+
int | Sequence[int] | np_ndarray_bool | np_ndarray_anyint | np_ndarray_float
23152317
),
23162318
) -> Series[float]: ...
23172319
@overload
@@ -2353,35 +2355,50 @@ class Series(IndexOpsMixin[S1], NDFrame):
23532355
axis: AxisIndex = 0,
23542356
) -> Series: ...
23552357
@overload
2358+
def rtruediv(
2359+
self,
2360+
other: Series[Never],
2361+
level: Level | None = None,
2362+
fill_value: float | None = None,
2363+
axis: AxisIndex = 0,
2364+
) -> Series: ...
2365+
@overload
23562366
def rtruediv(
23572367
self: Series[bool],
2358-
other: bool | np_ndarray_bool | Series[bool],
2368+
other: bool | np_ndarray_bool,
23592369
level: Level | None = None,
23602370
fill_value: float | None = None,
23612371
axis: AxisIndex = 0,
23622372
) -> Never: ...
23632373
@overload
2364-
def rtruediv(
2374+
def rtruediv( # pyright: ignore[reportOverlappingOverload]
23652375
self: Series[bool],
2366-
other: int | Sequence[int] | np_ndarray_anyint | np_ndarray_float | Series[int],
2376+
other: (
2377+
float
2378+
| Sequence[float]
2379+
| np_ndarray_anyint
2380+
| np_ndarray_float
2381+
| Series[int]
2382+
| Series[float]
2383+
),
23672384
level: Level | None = None,
23682385
fill_value: float | None = None,
23692386
axis: AxisIndex = 0,
23702387
) -> Series[float]: ...
23712388
@overload
2372-
def rtruediv( # type: ignore[overload-overlap]
2389+
def rtruediv(
23732390
self: Series[bool],
2374-
other: _T_NUM_NON_BOOL | Sequence[_T_NUM_NON_BOOL] | Series[_T_NUM_NON_BOOL],
2391+
other: complex | Sequence[complex] | Series[complex],
23752392
level: Level | None = None,
23762393
fill_value: float | None = None,
23772394
axis: AxisIndex = 0,
2378-
) -> Series[_T_NUM_NON_BOOL]: ...
2395+
) -> Series[complex]: ...
23792396
@overload
23802397
def rtruediv(
23812398
self: Series[int],
23822399
other: (
2383-
_T_INT
2384-
| Sequence[_T_INT]
2400+
int
2401+
| Sequence[int]
23852402
| np_ndarray_bool
23862403
| np_ndarray_anyint
23872404
| np_ndarray_float

tests/series/arithmetic/bool/test_truediv.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def test_truediv_pd_series() -> None:
191191
check(assert_type(c / left, "pd.Series[complex]"), pd.Series, np.complexfloating)
192192

193193
if TYPE_CHECKING_INVALID_USAGE:
194-
assert_type(left.truediv(b), Never)
194+
left.truediv(b) # type: ignore[arg-type] # pyright: ignore[reportArgumentType,reportCallIssue]
195195
check(assert_type(left.truediv(i), "pd.Series[float]"), pd.Series, np.floating)
196196
check(assert_type(left.truediv(f), "pd.Series[float]"), pd.Series, np.floating)
197197
check(
@@ -201,13 +201,13 @@ def test_truediv_pd_series() -> None:
201201
)
202202

203203
if TYPE_CHECKING_INVALID_USAGE:
204-
assert_type(left.div(b), Never)
204+
left.div(b) # type: ignore[arg-type] # pyright: ignore[reportArgumentType,reportCallIssue]
205205
check(assert_type(left.div(i), "pd.Series[float]"), pd.Series, np.floating)
206206
check(assert_type(left.div(f), "pd.Series[float]"), pd.Series, np.floating)
207207
check(assert_type(left.div(c), "pd.Series[complex]"), pd.Series, np.complexfloating)
208208

209209
if TYPE_CHECKING_INVALID_USAGE:
210-
assert_type(left.rtruediv(b), Never)
210+
left.rtruediv(b) # type: ignore[arg-type] # pyright: ignore[reportArgumentType,reportCallIssue]
211211
check(assert_type(left.rtruediv(i), "pd.Series[float]"), pd.Series, np.floating)
212212
check(assert_type(left.rtruediv(f), "pd.Series[float]"), pd.Series, np.floating)
213213
check(
@@ -217,7 +217,7 @@ def test_truediv_pd_series() -> None:
217217
)
218218

219219
if TYPE_CHECKING_INVALID_USAGE:
220-
assert_type(left.rdiv(b), Never)
220+
left.rdiv(b) # type: ignore[arg-type] # pyright: ignore[reportArgumentType,reportCallIssue]
221221
check(assert_type(left.rdiv(i), "pd.Series[float]"), pd.Series, np.floating)
222222
check(assert_type(left.rdiv(f), "pd.Series[float]"), pd.Series, np.floating)
223223
check(

0 commit comments

Comments
 (0)