Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions pandas-stubs/_libs/tslibs/timestamps.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ from pandas._libs.tslibs import (
Tick,
Timedelta,
)
from pandas._libs.tslibs.nattype import NaTType
from pandas._typing import (
PeriodFrequency,
ShapeT,
Expand Down Expand Up @@ -228,7 +229,7 @@ class Timestamp(datetime, SupportsIndex):
def __radd__(
self, other: np_ndarray[ShapeT, np.timedelta64]
) -> np_ndarray[ShapeT, np.datetime64]: ...
# TODO: pandas-dev/pandas-stubs#1432 test dt64
def __rsub__(self, other: datetime | np.datetime64) -> Timedelta: ...
@overload # type: ignore[override]
def __sub__(self, other: datetime | np.datetime64) -> Timedelta: ...
@overload
Expand Down Expand Up @@ -284,7 +285,15 @@ class Timestamp(datetime, SupportsIndex):
@property
def asm8(self) -> np.datetime64: ...
def tz_convert(self, tz: TimeZones) -> Self: ...
# TODO: pandas-dev/pandas-stubs#1432 could return NaT?
@overload
def tz_localize( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
self,
tz: TimeZones,
ambiguous: _Ambiguous = "raise",
*,
nonexistent: Literal["NaT"],
) -> Self | NaTType: ...
@overload
def tz_localize(
self,
tz: TimeZones,
Expand Down
4 changes: 2 additions & 2 deletions pandas-stubs/core/indexes/interval.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@ def interval_range(
) -> IntervalIndex[Interval[pd.Timestamp]]: ...
@overload
def interval_range(
*,
start: None = None,
*,
end: _TimestampLike,
periods: int | None = ...,
freq: Frequency | dt.timedelta | None = ...,
Expand All @@ -341,8 +341,8 @@ def interval_range(
) -> IntervalIndex[Interval[pd.Timedelta]]: ...
@overload
def interval_range(
*,
start: None = None,
*,
end: _TimedeltaLike,
periods: int | None = ...,
freq: Frequency | dt.timedelta | None = ...,
Expand Down
6 changes: 3 additions & 3 deletions pandas-stubs/io/orc.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from typing import Any

from fsspec.spec import AbstractFileSystem # pyright: ignore[reportMissingTypeStubs]
from pandas import DataFrame
from pyarrow.fs import FileSystem

from pandas._libs.lib import _NoDefaultDoNotUse
from pandas._typing import (
Expand All @@ -14,8 +16,6 @@ def read_orc(
path: FilePath | ReadBuffer[bytes],
columns: list[HashableT] | None = None,
dtype_backend: DtypeBackend | _NoDefaultDoNotUse = "numpy_nullable",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In 3.0 the default value will be switched from "numpy_nullable" to no_default. I think this can be confusing to users using the stable releases 2.x. What should we do @Dr-Irv ? Anyway, we can address this in a separate PR.

# TODO: pandas-dev/pandas-stubs#1432 type with the correct pyarrow types
# filesystem: pyarrow.fs.FileSystem | fsspec.spec.AbstractFileSystem
filesystem: Any | None = None,
filesystem: FileSystem | AbstractFileSystem | None = None,
**kwargs: Any,
) -> DataFrame: ...
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ beautifulsoup4 = ">=4.14.2"
html5lib = ">=1.1"
python-calamine = ">=0.2.0"
pyarrow-stubs = { version = ">=20.0.0.20250928", python = "<4" }
fsspec = "^2025.10.0"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
13 changes: 12 additions & 1 deletion tests/scalars/test_scalars.py
Original file line number Diff line number Diff line change
Expand Up @@ -1385,9 +1385,20 @@ def test_timestamp_misc_methods() -> None:
pd.Timestamp,
)
check(
assert_type(ts.tz_localize("US/Pacific", nonexistent="NaT"), pd.Timestamp),
assert_type(
ts.tz_localize("US/Pacific", nonexistent="NaT"), pd.Timestamp | NaTType
),
pd.Timestamp,
)
check(
assert_type(
pd.Timestamp(2025, 3, 9, 2, 30, 0).tz_localize(
"US/Eastern", nonexistent="NaT"
),
pd.Timestamp | NaTType,
),
NaTType,
)
check(
assert_type(ts.tz_localize("US/Pacific", nonexistent="raise"), pd.Timestamp),
pd.Timestamp,
Expand Down
4 changes: 4 additions & 0 deletions tests/test_timefuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,13 @@ def test_types_init() -> None:
def test_types_arithmetic() -> None:
ts = pd.to_datetime("2021-03-01")
ts2 = pd.to_datetime("2021-01-01")
ts_np = np.datetime64("2021-01-01")
delta = pd.to_timedelta("1 day")

check(assert_type(ts - ts2, pd.Timedelta), pd.Timedelta)
check(assert_type(ts - ts_np, pd.Timedelta), pd.Timedelta)
# TODO: pandas-dev/pandas-stubs#1432 mypy sees datetime.timedelta but pyright is correct
# check(assert_type(ts_np - ts, pd.Timedelta), pd.Timedelta)
Comment on lines +103 to +104
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see our __rsub__ is correct but mypy takes ts_np.__sub__ as a higher priority. This has happened a lot in Series and Index arithmetic. I think neither mypy nor pyright is correct, we should see Any here because of the discrepency. Do you have any suggestion to improve here, @Dr-Irv ?

check(assert_type(ts + delta, pd.Timestamp), pd.Timestamp)
check(assert_type(ts - delta, pd.Timestamp), pd.Timestamp)
check(assert_type(ts - dt.datetime(2021, 1, 3), pd.Timedelta), pd.Timedelta)
Expand Down