Skip to content

Commit 2dada6d

Browse files
committed
fix: even less mypy ignores
1 parent ad0ee10 commit 2dada6d

File tree

4 files changed

+29
-26
lines changed

4 files changed

+29
-26
lines changed

pandas-stubs/_typing.pyi

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -824,23 +824,29 @@ MaskType: TypeAlias = Series[bool] | np_ndarray_bool | list[bool]
824824

825825
# Scratch types for generics
826826

827-
SeriesDType: TypeAlias = (
827+
# Closure upon add, sub, mul
828+
SeriesDTypeClosure: TypeAlias = (
828829
str
829830
| bytes
830-
| datetime.date
831-
| datetime.time
832831
| bool
833832
| int
834833
| float
835834
| complex
836835
| Dtype
836+
| Interval
837+
| CategoricalDtype
838+
| list[str]
839+
)
840+
S1C = TypeVar("S1C", bound=SeriesDTypeClosure, default=Any)
841+
842+
SeriesDType: TypeAlias = (
843+
SeriesDTypeClosure
844+
| datetime.date
845+
| datetime.time
837846
| datetime.datetime # includes pd.Timestamp
838847
| datetime.timedelta # includes pd.Timedelta
839848
| Period
840-
| Interval
841-
| CategoricalDtype
842849
| BaseOffset
843-
| list[str]
844850
)
845851
S1 = TypeVar("S1", bound=SeriesDType, default=Any)
846852
# Like S1, but without `default=Any`.

pandas-stubs/core/series.pyi

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ from pandas._libs.tslibs.nattype import NaTType
104104
from pandas._libs.tslibs.offsets import DateOffset
105105
from pandas._typing import (
106106
S1,
107+
S1C,
107108
S2,
108109
AggFuncTypeBase,
109110
AggFuncTypeDictFrame,
@@ -186,29 +187,26 @@ from pandas.core.dtypes.dtypes import CategoricalDtype
186187

187188
from pandas.plotting import PlotAccessor
188189

189-
_T_FLOAT = TypeVar("_T_FLOAT", bound=float)
190190
_T_COMPLEX = TypeVar("_T_COMPLEX", bound=complex)
191191

192-
_scalar_timestamp: TypeAlias = datetime | np.datetime64 | Timestamp
192+
_scalar_timestamp: TypeAlias = date | datetime | np.datetime64
193193
_vector_timestamp: TypeAlias = (
194-
Sequence[datetime]
194+
Sequence[date]
195+
| Sequence[datetime]
195196
| Sequence[np.datetime64]
196-
| Sequence[Timestamp]
197197
| np.typing.NDArray[np.datetime64]
198198
| DatetimeIndex
199199
)
200200
_nonseries_timestamp: TypeAlias = _scalar_timestamp | _vector_timestamp
201201

202-
_scalar_timedelta: TypeAlias = timedelta | np.timedelta64 | BaseOffset | Timedelta
202+
_scalar_timedelta: TypeAlias = timedelta | np.timedelta64 | BaseOffset
203203
_vector_timedelta: TypeAlias = (
204204
Sequence[timedelta]
205205
| Sequence[np.timedelta64]
206-
| Sequence[Timedelta]
207206
| np.typing.NDArray[np.timedelta64]
208207
| TimedeltaIndex
209208
)
210209
_nonseries_timedelta: TypeAlias = _scalar_timedelta | _vector_timedelta
211-
_T_TIMESTAMP = TypeVar("_T_TIMESTAMP", bound=Timestamp)
212210

213211
class _iLocIndexerSeries(_iLocIndexer, Generic[S1]):
214212
# get item
@@ -1634,9 +1632,9 @@ class Series(IndexOpsMixin[S1], NDFrame):
16341632
# just failed to generate these so I couldn't match
16351633
# them up.
16361634
@overload
1637-
def __add__(self: Series[Never], other: Scalar | _ListLike | Series) -> Series: ... # type: ignore[overload-overlap]
1635+
def __add__(self: Series[Never], other: Scalar | _ListLike | Series) -> Series: ...
16381636
@overload
1639-
def __add__(self, other: Series[Never]) -> Series: ...
1637+
def __add__(self: Series[S1C], other: Series[Never]) -> Series: ...
16401638
@overload
16411639
def __add__(
16421640
self: Series[int], other: _T_COMPLEX | Sequence[_T_COMPLEX] | Series[_T_COMPLEX]
@@ -1671,10 +1669,10 @@ class Series(IndexOpsMixin[S1], NDFrame):
16711669
| np_ndarray_complex
16721670
),
16731671
) -> Series[complex]: ...
1674-
@overload
1675-
def __add__(
1676-
self: Series[Timestamp], other: _nonseries_timestamp # | Series[Timestamp]
1677-
) -> Never: ...
1672+
# @overload
1673+
# def __add__(
1674+
# self: Series[Timestamp], other: _nonseries_timestamp # | Series[Timestamp]
1675+
# ) -> Never: ...
16781676
@overload
16791677
def __add__(
16801678
self: Series[Timestamp],
@@ -1687,7 +1685,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
16871685
self: Series[Timedelta], other: _nonseries_timestamp | Series[Timestamp]
16881686
) -> Series[Timestamp]: ...
16891687
@overload
1690-
def __add__(self, other: S1 | Series[S1]) -> Self: ...
1688+
def __add__(self: Series[S1C], other: S1C | Series[S1C]) -> Series[S1C]: ...
16911689
@overload
16921690
def add(
16931691
self: Series[Never],
@@ -1937,7 +1935,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
19371935
@overload
19381936
def __mul__(self: Series[Never], other: num | _ListLike | Series) -> Series: ...
19391937
@overload
1940-
def __mul__(self, other: Series[Never]) -> Series: ... # type: ignore[overload-overlap]
1938+
def __mul__(self: Series[S1C], other: Series[Never]) -> Series: ... # type: ignore[overload-overlap]
19411939
@overload
19421940
def __mul__(
19431941
self: Series[int], other: _T_COMPLEX | Series[_T_COMPLEX]
@@ -1955,7 +1953,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
19551953
) -> Never: ...
19561954
@overload
19571955
def __mul__(
1958-
self: Series[_T_FLOAT], other: _nonseries_timedelta | TimedeltaSeries
1956+
self, other: timedelta | Timedelta | TimedeltaSeries | np.timedelta64
19591957
) -> TimedeltaSeries: ...
19601958
@overload
19611959
def __mul__(self, other: num | _ListLike | Series) -> Series: ...
@@ -2014,7 +2012,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
20142012
) -> Series[Timestamp]: ...
20152013
@overload
20162014
def __sub__(
2017-
self: Series[Timestamp], other: _nonseries_timestamp | Series[_T_TIMESTAMP]
2015+
self: Series[Timestamp], other: _nonseries_timestamp | Series[Timestamp]
20182016
) -> TimedeltaSeries: ...
20192017
@overload
20202018
def __sub__(self, other: S1 | Self) -> Self: ...

tests/test_frame.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3488,7 +3488,6 @@ def test_groupby_apply() -> None:
34883488
df = pd.DataFrame({"col1": [1, 2, 3], "col2": [4, 5, 6]})
34893489

34903490
def sum_mean(x: pd.DataFrame) -> float:
3491-
x.sum()
34923491
return x.sum().mean()
34933492

34943493
with pytest_warns_bounded(

tests/test_timefuncs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,9 @@ def test_fail_on_adding_two_timestamps() -> None:
320320
s1 = pd.Series(pd.to_datetime(["2022-05-01", "2022-06-01"]))
321321
s2 = pd.Series(pd.to_datetime(["2022-05-15", "2022-06-15"]))
322322
if TYPE_CHECKING_INVALID_USAGE:
323-
ssum = s1 + s2
323+
ssum: pd.Series = s1 + s2 # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
324324
ts = pd.Timestamp("2022-06-30")
325-
tsum = s1 + ts # type: ignore[var-annotated]
325+
tsum: pd.Series = s1 + ts # type: ignore[operator] # pyright: ignore[reportOperatorIssue]
326326

327327

328328
def test_dtindex_tzinfo() -> None:

0 commit comments

Comments
 (0)