Skip to content

Commit 367ee7d

Browse files
GH1432 Partial resolution
1 parent 2fdf7ed commit 367ee7d

File tree

5 files changed

+31
-6
lines changed

5 files changed

+31
-6
lines changed

pandas-stubs/_libs/tslibs/timestamps.pyi

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ from pandas._libs.tslibs import (
3232
Tick,
3333
Timedelta,
3434
)
35+
from pandas._libs.tslibs.nattype import NaTType
3536
from pandas._typing import (
3637
PeriodFrequency,
3738
ShapeT,
@@ -228,7 +229,7 @@ class Timestamp(datetime, SupportsIndex):
228229
def __radd__(
229230
self, other: np_ndarray[ShapeT, np.timedelta64]
230231
) -> np_ndarray[ShapeT, np.datetime64]: ...
231-
# TODO: pandas-dev/pandas-stubs#1432 test dt64
232+
def __rsub__(self, other: datetime | np.datetime64) -> Timedelta: ...
232233
@overload # type: ignore[override]
233234
def __sub__(self, other: datetime | np.datetime64) -> Timedelta: ...
234235
@overload
@@ -284,7 +285,15 @@ class Timestamp(datetime, SupportsIndex):
284285
@property
285286
def asm8(self) -> np.datetime64: ...
286287
def tz_convert(self, tz: TimeZones) -> Self: ...
287-
# TODO: pandas-dev/pandas-stubs#1432 could return NaT?
288+
@overload
289+
def tz_localize( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
290+
self,
291+
tz: TimeZones,
292+
ambiguous: _Ambiguous = "raise",
293+
*,
294+
nonexistent: Literal["NaT"],
295+
) -> Self | NaTType: ...
296+
@overload
288297
def tz_localize(
289298
self,
290299
tz: TimeZones,

pandas-stubs/io/orc.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from typing import Any
22

3+
from fsspec.spec import AbstractFileSystem # pyright: ignore[reportMissingTypeStubs]
34
from pandas import DataFrame
5+
from pyarrow.fs import FileSystem
46

57
from pandas._libs.lib import _NoDefaultDoNotUse
68
from pandas._typing import (
@@ -14,8 +16,6 @@ def read_orc(
1416
path: FilePath | ReadBuffer[bytes],
1517
columns: list[HashableT] | None = None,
1618
dtype_backend: DtypeBackend | _NoDefaultDoNotUse = "numpy_nullable",
17-
# TODO: pandas-dev/pandas-stubs#1432 type with the correct pyarrow types
18-
# filesystem: pyarrow.fs.FileSystem | fsspec.spec.AbstractFileSystem
19-
filesystem: Any | None = None,
19+
filesystem: FileSystem | AbstractFileSystem | None = None,
2020
**kwargs: Any,
2121
) -> DataFrame: ...

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ beautifulsoup4 = ">=4.14.2"
7070
html5lib = ">=1.1"
7171
python-calamine = ">=0.2.0"
7272
pyarrow-stubs = { version = ">=20.0.0.20250928", python = "<4" }
73+
fsspec = "^2025.10.0"
7374

7475
[build-system]
7576
requires = ["poetry-core>=1.0.0"]

tests/scalars/test_scalars.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1385,9 +1385,20 @@ def test_timestamp_misc_methods() -> None:
13851385
pd.Timestamp,
13861386
)
13871387
check(
1388-
assert_type(ts.tz_localize("US/Pacific", nonexistent="NaT"), pd.Timestamp),
1388+
assert_type(
1389+
ts.tz_localize("US/Pacific", nonexistent="NaT"), pd.Timestamp | NaTType
1390+
),
13891391
pd.Timestamp,
13901392
)
1393+
check(
1394+
assert_type(
1395+
pd.Timestamp(2025, 3, 9, 2, 30, 0).tz_localize(
1396+
"US/Eastern", nonexistent="NaT"
1397+
),
1398+
pd.Timestamp | NaTType,
1399+
),
1400+
NaTType,
1401+
)
13911402
check(
13921403
assert_type(ts.tz_localize("US/Pacific", nonexistent="raise"), pd.Timestamp),
13931404
pd.Timestamp,

tests/test_timefuncs.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,13 @@ def test_types_init() -> None:
9595
def test_types_arithmetic() -> None:
9696
ts = pd.to_datetime("2021-03-01")
9797
ts2 = pd.to_datetime("2021-01-01")
98+
ts_np = np.datetime64("2021-01-01")
9899
delta = pd.to_timedelta("1 day")
99100

100101
check(assert_type(ts - ts2, pd.Timedelta), pd.Timedelta)
102+
check(assert_type(ts - ts_np, pd.Timedelta), pd.Timedelta)
103+
# TODO: pandas-dev/pandas-stubs#1432 mypy sees datetime.timedelta but pyright is correct
104+
# check(assert_type(ts_np - ts, pd.Timedelta), pd.Timedelta)
101105
check(assert_type(ts + delta, pd.Timestamp), pd.Timestamp)
102106
check(assert_type(ts - delta, pd.Timestamp), pd.Timestamp)
103107
check(assert_type(ts - dt.datetime(2021, 1, 3), pd.Timedelta), pd.Timedelta)

0 commit comments

Comments
 (0)