Skip to content

Commit 085653b

Browse files
loicdiridollouMarcoGorellicmp0xff
authored
GH1432 Partial resolution for some TODOs (#1492)
* GH1432 Partial resolution * GH1432 PR Feedback * type Index methods: putmask, asof, asof_locs, sort_values, get_indexer_non_unique, get_indexer_for, map, get_slice_bound (#1505) * type Index methods: putmask, asof, asof_locs, sort_values, get_indexer_non_unique, get_indexer_for, map, get_slice_bound * remove redundant `IntervalIndexer.get_indexer_non_unique` * slice_locs can return either `np.integer` or `int` * fix slice_locs test * Apply suggestions from code review Co-authored-by: Yi-Fan Wang <cmp0xff@users.noreply.github.com> * np.integer -> np.intp * test more mask types for `putmask` * Apply suggestions from code review Co-authored-by: Yi-Fan Wang <cmp0xff@users.noreply.github.com> * test asof with str --------- Co-authored-by: Yi-Fan Wang <cmp0xff@users.noreply.github.com> * GH1432 PR Feedback * FIX: #1508 numpy 1darrays in tests (#1512) fix: #1508 numpy arrays in tests * GH1484 Upgrade ty (#1509) * GH1484 Upgrade ty * GH1484 Fix formatting * GH1484 Update PR * GH1432 Partial resolution * GH1432 PR Feedback * Update tests/test_timefuncs.py Co-authored-by: Yi-Fan Wang <cmp0xff@users.noreply.github.com> --------- Co-authored-by: Marco Edward Gorelli <33491632+MarcoGorelli@users.noreply.github.com> Co-authored-by: Yi-Fan Wang <cmp0xff@users.noreply.github.com>
1 parent c616fb5 commit 085653b

File tree

5 files changed

+40
-6
lines changed

5 files changed

+40
-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,
@@ -236,7 +237,7 @@ class Timestamp(datetime, SupportsIndex):
236237
def __radd__(
237238
self, other: np_ndarray[ShapeT, np.timedelta64]
238239
) -> np_ndarray[ShapeT, np.datetime64]: ...
239-
# TODO: pandas-dev/pandas-stubs#1432 test dt64
240+
def __rsub__(self, other: datetime | np.datetime64) -> Timedelta: ...
240241
@overload # type: ignore[override]
241242
def __sub__(self, other: datetime | np.datetime64) -> Timedelta: ...
242243
@overload
@@ -292,7 +293,15 @@ class Timestamp(datetime, SupportsIndex):
292293
@property
293294
def asm8(self) -> np.datetime64: ...
294295
def tz_convert(self, tz: TimeZones) -> Self: ...
295-
# TODO: pandas-dev/pandas-stubs#1432 could return NaT?
296+
@overload
297+
def tz_localize( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
298+
self,
299+
tz: TimeZones,
300+
ambiguous: _Ambiguous = "raise",
301+
*,
302+
nonexistent: Literal["NaT"],
303+
) -> Self | NaTType: ...
304+
@overload
296305
def tz_localize(
297306
self,
298307
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
@@ -1386,9 +1386,20 @@ def test_timestamp_misc_methods() -> None:
13861386
pd.Timestamp,
13871387
)
13881388
check(
1389-
assert_type(ts.tz_localize("US/Pacific", nonexistent="NaT"), pd.Timestamp),
1389+
assert_type(
1390+
ts.tz_localize("US/Pacific", nonexistent="NaT"), pd.Timestamp | NaTType
1391+
),
13901392
pd.Timestamp,
13911393
)
1394+
check(
1395+
assert_type(
1396+
pd.Timestamp(2025, 3, 9, 2, 30, 0).tz_localize(
1397+
"US/Eastern", nonexistent="NaT"
1398+
),
1399+
pd.Timestamp | NaTType,
1400+
),
1401+
NaTType,
1402+
)
13921403
check(
13931404
assert_type(ts.tz_localize("US/Pacific", nonexistent="raise"), pd.Timestamp),
13941405
pd.Timestamp,

tests/test_timefuncs.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,26 @@ 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")
99+
ts_np_time = np.datetime64("2021-01-01 08:00:05")
98100
delta = pd.to_timedelta("1 day")
99101

100102
check(assert_type(ts - ts2, pd.Timedelta), pd.Timedelta)
103+
check(assert_type(ts - ts_np, pd.Timedelta), pd.Timedelta)
104+
check(assert_type(ts - ts_np_time, 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)
104108

109+
if TYPE_CHECKING_INVALID_USAGE:
110+
# TODO: pandas-dev/pandas-stubs#1511 numpy.datetime64.__sub__ gives datetime.timedelta, which has higher priority
111+
assert_type(
112+
ts_np - ts, dt.timedelta # pyright: ignore[reportAssertTypeFailure]
113+
)
114+
assert_type(
115+
ts_np_time - ts, dt.timedelta # pyright: ignore[reportAssertTypeFailure]
116+
)
117+
105118

106119
def test_types_comparison() -> None:
107120
ts = pd.to_datetime("2021-03-01")

0 commit comments

Comments
 (0)