Skip to content

Commit 8ecfc5a

Browse files
Dr-Irvtwoertwein
authored andcommitted
Remove use of Never (pandas-dev#506)
1 parent e100576 commit 8ecfc5a

File tree

3 files changed

+24
-38
lines changed

3 files changed

+24
-38
lines changed

pandas-stubs/core/indexes/interval.pyi

+14-19
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ from pandas.core.series import (
1818
TimedeltaSeries,
1919
TimestampSeries,
2020
)
21-
from typing_extensions import (
22-
Never,
23-
TypeAlias,
24-
)
21+
from typing_extensions import TypeAlias
2522

2623
from pandas._libs.interval import (
2724
Interval as Interval,
@@ -260,31 +257,29 @@ class IntervalIndex(IntervalMixin, ExtensionIndex, Generic[IntervalT]):
260257
# override is due to additional types for comparison
261258
# misc is due to overlap with object below
262259
@overload # type: ignore[override]
263-
def __gt__( # type: ignore[misc]
260+
def __gt__(
264261
self, other: IntervalT | IntervalIndex[IntervalT]
265262
) -> np_ndarray_bool: ...
266263
@overload
267-
def __gt__(self, other: pd.Series[IntervalT]) -> pd.Series[bool]: ... # type: ignore[misc]
268-
@overload
269-
def __gt__(self, other: object) -> Never: ...
264+
def __gt__(self, other: pd.Series[IntervalT]) -> pd.Series[bool]: ...
270265
@overload # type: ignore[override]
271-
def __ge__(self, other: IntervalT | IntervalIndex[IntervalT]) -> np_ndarray_bool: ... # type: ignore[misc]
272-
@overload
273-
def __ge__(self, other: pd.Series[IntervalT]) -> pd.Series[bool]: ... # type: ignore[misc]
266+
def __ge__(
267+
self, other: IntervalT | IntervalIndex[IntervalT]
268+
) -> np_ndarray_bool: ...
274269
@overload
275-
def __ge__(self, other: object) -> Never: ...
270+
def __ge__(self, other: pd.Series[IntervalT]) -> pd.Series[bool]: ...
276271
@overload # type: ignore[override]
277-
def __le__(self, other: IntervalT | IntervalIndex[IntervalT]) -> np_ndarray_bool: ... # type: ignore[misc]
278-
@overload
279-
def __le__(self, other: pd.Series[IntervalT]) -> pd.Series[bool]: ... # type: ignore[misc]
272+
def __le__(
273+
self, other: IntervalT | IntervalIndex[IntervalT]
274+
) -> np_ndarray_bool: ...
280275
@overload
281-
def __le__(self, other: object) -> Never: ...
276+
def __le__(self, other: pd.Series[IntervalT]) -> pd.Series[bool]: ...
282277
@overload # type: ignore[override]
283-
def __lt__(self, other: IntervalT | IntervalIndex[IntervalT]) -> np_ndarray_bool: ... # type: ignore[misc]
278+
def __lt__(
279+
self, other: IntervalT | IntervalIndex[IntervalT]
280+
) -> np_ndarray_bool: ...
284281
@overload
285282
def __lt__(self, other: pd.Series[IntervalT]) -> bool: ... # type: ignore[misc]
286-
@overload
287-
def __lt__(self, other: object) -> Never: ...
288283
@overload # type: ignore[override]
289284
def __eq__(self, other: IntervalT | IntervalIndex[IntervalT]) -> np_ndarray_bool: ... # type: ignore[misc]
290285
@overload

pandas-stubs/core/series.pyi

+6-12
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,7 @@ from pandas.core.window.rolling import (
6565
Rolling,
6666
Window,
6767
)
68-
from typing_extensions import (
69-
Never,
70-
TypeAlias,
71-
)
68+
from typing_extensions import TypeAlias
7269
import xarray as xr
7370

7471
from pandas._libs.interval import Interval
@@ -1814,8 +1811,8 @@ class TimestampSeries(Series[Timestamp]):
18141811
@property
18151812
def dt(self) -> TimestampProperties: ... # type: ignore[override]
18161813
def __add__(self, other: TimedeltaSeries | np.timedelta64) -> TimestampSeries: ... # type: ignore[override]
1817-
def __mul__(self, other: TimestampSeries | np.timedelta64 | TimedeltaSeries) -> Never: ... # type: ignore[override]
1818-
def __truediv__(self, other: TimestampSeries | np.timedelta64 | TimedeltaSeries) -> Never: ... # type: ignore[override]
1814+
def __mul__(self, other: int | float | Series[int] | Series[float] | Sequence[int | float]) -> TimestampSeries: ... # type: ignore[override]
1815+
def __truediv__(self, other: int | float | Series[int] | Series[float] | Sequence[int | float]) -> TimestampSeries: ... # type: ignore[override]
18191816
def mean( # type: ignore[override]
18201817
self,
18211818
axis: SeriesAxisType | None = ...,
@@ -1853,12 +1850,9 @@ class TimedeltaSeries(Series[Timedelta]):
18531850
@overload
18541851
def __add__(self, other: Timedelta | np.timedelta64) -> TimedeltaSeries: ...
18551852
def __radd__(self, other: Timestamp | TimestampSeries) -> TimestampSeries: ... # type: ignore[override]
1856-
@overload # type: ignore[override]
1857-
def __mul__(
1858-
self, other: TimestampSeries | np.timedelta64 | Timedelta | TimedeltaSeries
1859-
) -> Never: ...
1860-
@overload
1861-
def __mul__(self, other: num) -> TimedeltaSeries: ...
1853+
def __mul__( # type: ignore[override]
1854+
self, other: num | Sequence[num] | Series[int] | Series[float]
1855+
) -> TimedeltaSeries: ...
18621856
def __sub__( # type: ignore[override]
18631857
self, other: Timedelta | TimedeltaSeries | TimedeltaIndex | np.timedelta64
18641858
) -> TimedeltaSeries: ...

tests/test_timefuncs.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414
import pandas as pd
1515
from pandas.core.indexes.numeric import IntegerIndex
1616
import pytz
17-
from typing_extensions import (
18-
Never,
19-
assert_type,
20-
)
17+
from typing_extensions import assert_type
2118

2219
from pandas._libs import NaTType
2320
from pandas._libs.tslibs import BaseOffset
@@ -1088,9 +1085,9 @@ def test_timedelta64_and_arithmatic_operator() -> None:
10881085
check(assert_type((s3 + td), "TimedeltaSeries"), pd.Series, pd.Timedelta)
10891086
check(assert_type((s3 / td), "pd.Series[float]"), pd.Series, float)
10901087
if TYPE_CHECKING_INVALID_USAGE:
1091-
assert_type((s1 * td), Never) # pyright: ignore[reportGeneralTypeIssues]
1092-
assert_type((s1 / td), Never) # pyright: ignore[reportGeneralTypeIssues]
1093-
assert_type((s3 * td), Never) # pyright: ignore[reportGeneralTypeIssues]
1088+
r1 = s1 * td # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]
1089+
r2 = s1 / td # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]
1090+
r3 = s3 * td # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]
10941091

10951092

10961093
def test_timedeltaseries_add_timestampseries() -> None:

0 commit comments

Comments
 (0)