Skip to content

Commit cd78cbb

Browse files
authored
remove np.datetime64 from S1, make adding two TimestampSeries fail (#527)
remove np.datetime64 from S1
1 parent 09a61d5 commit cd78cbb

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

pandas-stubs/_libs/tslibs/timestamps.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,15 @@ class Timestamp(datetime):
217217
@overload
218218
def __eq__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[misc] # pyright: ignore[reportOverlappingOverload]
219219
@overload
220-
def __eq__(self, other: TimestampSeries | Series[np.datetime64]) -> Series[bool]: ... # type: ignore[misc]
220+
def __eq__(self, other: TimestampSeries) -> Series[bool]: ... # type: ignore[misc]
221221
@overload
222222
def __eq__(self, other: npt.NDArray[np.datetime64] | Index) -> np_ndarray_bool: ... # type: ignore[misc]
223223
@overload
224224
def __eq__(self, other: object) -> Literal[False]: ...
225225
@overload
226226
def __ne__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[misc] # pyright: ignore[reportOverlappingOverload]
227227
@overload
228-
def __ne__(self, other: TimestampSeries | Series[np.datetime64]) -> Series[bool]: ... # type: ignore[misc]
228+
def __ne__(self, other: TimestampSeries) -> Series[bool]: ... # type: ignore[misc]
229229
@overload
230230
def __ne__(self, other: npt.NDArray[np.datetime64] | Index) -> np_ndarray_bool: ... # type: ignore[misc]
231231
@overload

pandas-stubs/_typing.pyi

-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ S1 = TypeVar(
207207
complex,
208208
Timestamp,
209209
Timedelta,
210-
np.datetime64,
211210
Period,
212211
Interval[int],
213212
Interval[float],

pandas-stubs/core/series.pyi

+11-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ class _LocIndexerSeries(_LocIndexer, Generic[S1]):
178178
) -> None: ...
179179

180180
class Series(IndexOpsMixin, NDFrame, Generic[S1]):
181-
182181
_ListLike: TypeAlias = Union[ArrayLike, dict[_str, np.ndarray], list, tuple, Index]
183182
__hash__: ClassVar[None]
184183

@@ -193,6 +192,16 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
193192
fastpath: bool = ...,
194193
) -> TimestampSeries: ...
195194
@overload
195+
def __new__(
196+
cls,
197+
data: _ListLike,
198+
dtype: Literal["datetime64[ns]"],
199+
index: Axes | None = ...,
200+
name: Hashable | None = ...,
201+
copy: bool = ...,
202+
fastpath: bool = ...,
203+
) -> TimestampSeries: ...
204+
@overload
196205
def __new__(
197206
cls,
198207
data: PeriodIndex,
@@ -1800,6 +1809,7 @@ class TimestampSeries(Series[Timestamp]):
18001809
@property
18011810
def dt(self) -> TimestampProperties: ... # type: ignore[override]
18021811
def __add__(self, other: TimedeltaSeries | np.timedelta64) -> TimestampSeries: ... # type: ignore[override]
1812+
def __radd__(self, other: TimedeltaSeries | np.timedelta64) -> TimestampSeries: ... # type: ignore[override]
18031813
def __mul__(self, other: int | float | Series[int] | Series[float] | Sequence[int | float]) -> TimestampSeries: ... # type: ignore[override]
18041814
def __truediv__(self, other: int | float | Series[int] | Series[float] | Sequence[int | float]) -> TimestampSeries: ... # type: ignore[override]
18051815
def mean( # type: ignore[override]

tests/test_scalars.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444

4545
from pandas._typing import np_ndarray_bool
4646
else:
47-
4847
np_ndarray_bool = npt.NDArray[np.bool_]
4948
TimedeltaSeries: TypeAlias = pd.Series
5049
TimestampSeries: TypeAlias = pd.Series
@@ -386,7 +385,6 @@ def test_interval_cmp():
386385

387386

388387
def test_timedelta_construction() -> None:
389-
390388
check(assert_type(pd.Timedelta(1, "H"), pd.Timedelta), pd.Timedelta)
391389
check(assert_type(pd.Timedelta(1, "T"), pd.Timedelta), pd.Timedelta)
392390
check(assert_type(pd.Timedelta(1, "S"), pd.Timedelta), pd.Timedelta)
@@ -1078,7 +1076,6 @@ def test_timedelta_cmp_rhs() -> None:
10781076

10791077

10801078
def test_timestamp_construction() -> None:
1081-
10821079
check(assert_type(pd.Timestamp("2000-1-1"), pd.Timestamp), pd.Timestamp)
10831080
check(
10841081
assert_type(pd.Timestamp("2000-1-1", tz="US/Pacific"), pd.Timestamp),
@@ -1256,9 +1253,7 @@ def test_timestamp_cmp() -> None:
12561253
c_dt_datetime = dt.datetime(year=2000, month=1, day=1)
12571254
c_datetimeindex = pd.DatetimeIndex(["2000-1-1"])
12581255
c_np_ndarray_dt64 = np_dt64_arr
1259-
c_series_dt64: pd.Series[np.datetime64] = pd.Series(
1260-
[1, 2, 3], dtype="datetime64[ns]"
1261-
)
1256+
c_series_dt64: TimestampSeries = pd.Series([1, 2, 3], dtype="datetime64[ns]")
12621257
c_series_timestamp = pd.Series(pd.DatetimeIndex(["2000-1-1"]))
12631258
check(assert_type(c_series_timestamp, TimestampSeries), pd.Series, pd.Timestamp)
12641259
# Use xor to ensure one is True and the other is False

tests/test_timefuncs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def test_fail_on_adding_two_timestamps() -> None:
268268
s1 = pd.Series(pd.to_datetime(["2022-05-01", "2022-06-01"]))
269269
s2 = pd.Series(pd.to_datetime(["2022-05-15", "2022-06-15"]))
270270
if TYPE_CHECKING_INVALID_USAGE:
271-
ssum: pd.Series = s1 + s2 # type: ignore[operator]
271+
ssum: pd.Series = s1 + s2 # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]
272272
ts = pd.Timestamp("2022-06-30")
273273
tsum: pd.Series = s1 + ts # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]
274274

0 commit comments

Comments
 (0)