Skip to content
Merged
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
40 changes: 21 additions & 19 deletions pandas-stubs/_libs/tslibs/period.pyi
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
import datetime
import sys
from typing import (
Literal,
TypeAlias,
overload,
)

import numpy as np
from pandas import (
Index,
PeriodIndex,
Series,
Timedelta,
TimedeltaIndex,
)
from pandas.core.indexes.base import Index
from pandas.core.indexes.period import PeriodIndex
from pandas.core.indexes.timedeltas import TimedeltaIndex
from pandas.core.series import Series
from typing_extensions import Self

from pandas._libs.tslibs import NaTType
from pandas._libs.tslibs.offsets import (
BaseOffset,
)
from pandas._libs.tslibs.offsets import BaseOffset
from pandas._libs.tslibs.timedeltas import Timedelta
from pandas._libs.tslibs.timestamps import Timestamp
from pandas._typing import (
PeriodFrequency,
Expand Down Expand Up @@ -79,7 +76,7 @@ class Period(PeriodMixin):
@overload
def __sub__(self, other: _PeriodAddSub) -> Period: ...
@overload
def __sub__(self, other: Period) -> BaseOffset: ...
def __sub__(self, other: Self) -> BaseOffset: ...
@overload
def __sub__(self, other: NaTType) -> NaTType: ...
@overload
Expand All @@ -98,8 +95,13 @@ class Period(PeriodMixin):
def __add__(self, other: Index) -> PeriodIndex: ...
# Ignored due to indecipherable error from mypy:
# Forward operator "__add__" is not callable [misc]
@overload
def __radd__(self, other: _PeriodAddSub) -> Self: ... # type: ignore[misc]
if sys.version_info >= (3, 11):
@overload
def __radd__(self, other: _PeriodAddSub) -> Self: ...
else:
@overload
def __radd__(self, other: _PeriodAddSub) -> Self: ... # type: ignore[misc]

@overload
def __radd__(self, other: NaTType) -> NaTType: ...
# Real signature is -> PeriodIndex, but conflicts with Index.__add__
Expand All @@ -111,7 +113,7 @@ class Period(PeriodMixin):
# ignore[misc] here because we know all other comparisons
# are False, so we use Literal[False]
@overload
def __eq__(self, other: Period) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
def __eq__(self, other: Self) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
@overload
def __eq__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
@overload
Expand All @@ -121,7 +123,7 @@ class Period(PeriodMixin):
@overload
def __eq__(self, other: object) -> Literal[False]: ...
@overload
def __ge__(self, other: Period) -> bool: ...
def __ge__(self, other: Self) -> bool: ...
@overload
def __ge__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
@overload
Expand All @@ -133,7 +135,7 @@ class Period(PeriodMixin):
self, other: np_ndarray[ShapeT, np.object_]
) -> np_ndarray[ShapeT, np.bool]: ...
@overload
def __gt__(self, other: Period) -> bool: ...
def __gt__(self, other: Self) -> bool: ...
@overload
def __gt__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
@overload
Expand All @@ -145,7 +147,7 @@ class Period(PeriodMixin):
self, other: np_ndarray[ShapeT, np.object_]
) -> np_ndarray[ShapeT, np.bool]: ...
@overload
def __le__(self, other: Period) -> bool: ...
def __le__(self, other: Self) -> bool: ...
@overload
def __le__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
@overload
Expand All @@ -157,7 +159,7 @@ class Period(PeriodMixin):
self, other: np_ndarray[ShapeT, np.object_]
) -> np_ndarray[ShapeT, np.bool]: ...
@overload
def __lt__(self, other: Period) -> bool: ...
def __lt__(self, other: Self) -> bool: ...
@overload
def __lt__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
@overload
Expand All @@ -171,7 +173,7 @@ class Period(PeriodMixin):
# ignore[misc] here because we know all other comparisons
# are False, so we use Literal[False]
@overload
def __ne__(self, other: Period) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
def __ne__(self, other: Self) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
@overload
def __ne__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
@overload
Expand Down
55 changes: 24 additions & 31 deletions pandas-stubs/_libs/tslibs/timedeltas.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,14 @@ from typing import (
)

import numpy as np
import pandas as pd
from pandas import (
DatetimeIndex,
Index,
PeriodIndex,
Series,
TimedeltaIndex,
)
from pandas.core.indexes.base import Index
from pandas.core.indexes.datetimes import DatetimeIndex
from pandas.core.indexes.period import PeriodIndex
from pandas.core.indexes.timedeltas import TimedeltaIndex
from pandas.core.series import Series
from typing_extensions import Self

from pandas._libs.tslibs import (
NaTType,
)
from pandas._libs.tslibs import NaTType
from pandas._libs.tslibs.period import Period
from pandas._libs.tslibs.timestamps import Timestamp
from pandas._typing import (
Expand Down Expand Up @@ -131,7 +126,7 @@ class Timedelta(timedelta):
def to_timedelta64(self) -> np.timedelta64: ...
@property
def asm8(self) -> np.timedelta64: ...
# TODO: round/floor/ceil could return NaT?
# TODO: pandas-dev/pandas-stubs#1432 round/floor/ceil could return NaT?
def round(self, freq: Frequency) -> Self: ...
def floor(self, freq: Frequency) -> Self: ...
def ceil(self, freq: Frequency) -> Self: ...
Expand Down Expand Up @@ -174,17 +169,17 @@ class Timedelta(timedelta):
) -> np_ndarray[ShapeT, np.datetime64]: ...
# Override due to more types supported than timedelta
@overload # type: ignore[override]
def __sub__(self, other: timedelta | Timedelta | np.timedelta64) -> Self: ...
def __sub__(self, other: timedelta | np.timedelta64 | Self) -> Self: ...
@overload
def __sub__(self, other: NaTType) -> NaTType: ...
@overload
def __sub__(
self, other: np_ndarray[ShapeT, np.timedelta64]
) -> np_ndarray[ShapeT, np.timedelta64]: ...
@overload
def __sub__(self, other: pd.TimedeltaIndex) -> TimedeltaIndex: ...
def __sub__(self, other: TimedeltaIndex) -> TimedeltaIndex: ...
@overload
def __rsub__(self, other: timedelta | Timedelta | np.timedelta64) -> Self: ...
def __rsub__(self, other: timedelta | np.timedelta64 | Self) -> Self: ...
@overload
def __rsub__(self, other: datetime | Timestamp | np.datetime64) -> Timestamp: ... # type: ignore[misc]
@overload
Expand All @@ -204,7 +199,7 @@ class Timedelta(timedelta):
self, other: np_ndarray[ShapeT, np.timedelta64]
) -> np_ndarray[ShapeT, np.timedelta64]: ...
@overload
def __rsub__(self, other: pd.TimedeltaIndex) -> pd.TimedeltaIndex: ...
def __rsub__(self, other: TimedeltaIndex) -> TimedeltaIndex: ...
def __neg__(self) -> Self: ...
def __pos__(self) -> Self: ...
def __abs__(self) -> Self: ...
Expand All @@ -224,7 +219,7 @@ class Timedelta(timedelta):
# Override due to more types supported than timedelta
# error: Signature of "__floordiv__" incompatible with supertype "timedelta"
@overload # type: ignore[override]
def __floordiv__(self, other: timedelta | Timedelta | np.timedelta64) -> int: ...
def __floordiv__(self, other: timedelta | np.timedelta64 | Self) -> int: ...
@overload
def __floordiv__(self, other: float) -> Self: ...
@overload
Expand Down Expand Up @@ -273,9 +268,9 @@ class Timedelta(timedelta):
def __rtruediv__(self, other: timedelta | Timedelta | NaTType) -> float: ...
# Override due to more types supported than timedelta
@overload
def __eq__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
def __eq__(self, other: timedelta | np.timedelta64 | Self) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
@overload
def __eq__(self, other: Series[pd.Timedelta]) -> Series[bool]: ... # type: ignore[overload-overlap]
def __eq__(self, other: Series[Timedelta]) -> Series[bool]: ... # type: ignore[overload-overlap]
@overload
def __eq__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
@overload
Expand All @@ -286,9 +281,9 @@ class Timedelta(timedelta):
def __eq__(self, other: object) -> Literal[False]: ...
# Override due to more types supported than timedelta
@overload
def __ne__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
def __ne__(self, other: timedelta | np.timedelta64 | Self) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
@overload
def __ne__(self, other: Series[pd.Timedelta]) -> Series[bool]: ... # type: ignore[overload-overlap]
def __ne__(self, other: Series[Timedelta]) -> Series[bool]: ... # type: ignore[overload-overlap]
@overload
def __ne__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
@overload
Expand All @@ -315,52 +310,50 @@ class Timedelta(timedelta):
self, other: Series[int] | Series[float] | Series[Timedelta]
) -> Series[Timedelta]: ...
def __divmod__(self, other: timedelta) -> tuple[int, Timedelta]: ...
# Mypy complains Forward operator "<inequality op>" is not callable, so ignore misc
# for le, lt ge and gt
# Override due to more types supported than timedelta
@overload # type: ignore[override]
def __le__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[misc]
def __le__(self, other: timedelta | np.timedelta64 | Self) -> bool: ...
@overload
def __le__(self, other: TimedeltaIndex) -> np_1darray[np.bool]: ...
@overload
def __le__(
self, other: np_ndarray[ShapeT, np.timedelta64]
) -> np_ndarray[ShapeT, np.bool_]: ...
@overload
def __le__(self, other: Series[pd.Timedelta]) -> Series[bool]: ...
def __le__(self, other: Series[Timedelta]) -> Series[bool]: ...
# Override due to more types supported than timedelta
@overload # type: ignore[override]
def __lt__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[misc]
def __lt__(self, other: timedelta | np.timedelta64 | Self) -> bool: ...
@overload
def __lt__(self, other: TimedeltaIndex) -> np_1darray[np.bool]: ...
@overload
def __lt__(
self, other: np_ndarray[ShapeT, np.timedelta64]
) -> np_ndarray[ShapeT, np.bool_]: ...
@overload
def __lt__(self, other: Series[pd.Timedelta]) -> Series[bool]: ...
def __lt__(self, other: Series[Timedelta]) -> Series[bool]: ...
# Override due to more types supported than timedelta
@overload # type: ignore[override]
def __ge__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[misc]
def __ge__(self, other: timedelta | np.timedelta64 | Self) -> bool: ...
@overload
def __ge__(self, other: TimedeltaIndex) -> np_1darray[np.bool]: ...
@overload
def __ge__(
self, other: np_ndarray[ShapeT, np.timedelta64]
) -> np_ndarray[ShapeT, np.bool_]: ...
@overload
def __ge__(self, other: Series[pd.Timedelta]) -> Series[bool]: ...
def __ge__(self, other: Series[Timedelta]) -> Series[bool]: ...
# Override due to more types supported than timedelta
@overload # type: ignore[override]
def __gt__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[misc]
def __gt__(self, other: timedelta | np.timedelta64 | Self) -> bool: ...
@overload
def __gt__(self, other: TimedeltaIndex) -> np_1darray[np.bool]: ...
@overload
def __gt__(
self, other: np_ndarray[ShapeT, np.timedelta64]
) -> np_ndarray[ShapeT, np.bool_]: ...
@overload
def __gt__(self, other: Series[pd.Timedelta]) -> Series[bool]: ...
def __gt__(self, other: Series[Timedelta]) -> Series[bool]: ...
def __hash__(self) -> int: ...
def isoformat(self) -> str: ...
def to_numpy(self) -> np.timedelta64: ...
Expand Down
18 changes: 9 additions & 9 deletions pandas-stubs/_libs/tslibs/timestamps.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class Timestamp(datetime, SupportsIndex):
# Mypy complains Forward operator "<inequality op>" is not callable, so ignore misc
# for le, lt ge and gt
@overload # type: ignore[override]
def __le__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[misc]
def __le__(self, other: datetime | np.datetime64 | Self) -> bool: ...
@overload
def __le__(self, other: DatetimeIndex) -> np_1darray[np.bool]: ...
@overload
Expand All @@ -185,7 +185,7 @@ class Timestamp(datetime, SupportsIndex):
@overload
def __le__(self, other: Series[Timestamp]) -> Series[bool]: ...
@overload # type: ignore[override]
def __lt__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[misc]
def __lt__(self, other: datetime | np.datetime64 | Self) -> bool: ...
@overload
def __lt__(self, other: DatetimeIndex) -> np_1darray[np.bool]: ...
@overload
Expand All @@ -195,7 +195,7 @@ class Timestamp(datetime, SupportsIndex):
@overload
def __lt__(self, other: Series[Timestamp]) -> Series[bool]: ...
@overload # type: ignore[override]
def __ge__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[misc]
def __ge__(self, other: datetime | np.datetime64 | Self) -> bool: ...
@overload
def __ge__(self, other: DatetimeIndex) -> np_1darray[np.bool]: ...
@overload
Expand All @@ -205,7 +205,7 @@ class Timestamp(datetime, SupportsIndex):
@overload
def __ge__(self, other: Series[Timestamp]) -> Series[bool]: ...
@overload # type: ignore[override]
def __gt__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[misc]
def __gt__(self, other: datetime | np.datetime64 | Self) -> bool: ...
@overload
def __gt__(self, other: DatetimeIndex) -> np_1darray[np.bool]: ...
@overload
Expand All @@ -231,7 +231,7 @@ class Timestamp(datetime, SupportsIndex):
def __radd__(
self, other: np_ndarray[ShapeT, np.timedelta64]
) -> np_ndarray[ShapeT, np.datetime64]: ...
# TODO: test dt64
# TODO: pandas-dev/pandas-stubs#1432 test dt64
@overload # type: ignore[override]
def __sub__(self, other: datetime | np.datetime64) -> Timedelta: ...
@overload
Expand All @@ -243,7 +243,7 @@ class Timestamp(datetime, SupportsIndex):
self, other: np_ndarray[ShapeT, np.timedelta64]
) -> np_ndarray[ShapeT, np.datetime64]: ...
@overload
def __eq__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
def __eq__(self, other: datetime | np.datetime64 | Self) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
@overload
def __eq__(self, other: Series[Timestamp]) -> Series[bool]: ... # type: ignore[overload-overlap]
@overload
Expand All @@ -253,7 +253,7 @@ class Timestamp(datetime, SupportsIndex):
@overload
def __eq__(self, other: object) -> Literal[False]: ...
@overload
def __ne__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
def __ne__(self, other: datetime | np.datetime64 | Self) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
@overload
def __ne__(self, other: Series[Timestamp]) -> Series[bool]: ... # type: ignore[overload-overlap]
@overload
Expand Down Expand Up @@ -287,15 +287,15 @@ class Timestamp(datetime, SupportsIndex):
@property
def asm8(self) -> np.datetime64: ...
def tz_convert(self, tz: TimeZones) -> Self: ...
# TODO: could return NaT?
# TODO: pandas-dev/pandas-stubs#1432 could return NaT?
def tz_localize(
self,
tz: TimeZones,
ambiguous: _Ambiguous = "raise",
nonexistent: TimestampNonexistent = "raise",
) -> Self: ...
def normalize(self) -> Self: ...
# TODO: round/floor/ceil could return NaT?
# TODO: pandas-dev/pandas-stubs#1432 round/floor/ceil could return NaT?
def round(
self,
freq: str,
Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/io/orc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def read_orc(
path: FilePath | ReadBuffer[bytes],
columns: list[HashableT] | None = None,
dtype_backend: DtypeBackend | _NoDefaultDoNotUse = "numpy_nullable",
# TODO: type with the correct pyarrow types
# TODO: pandas-dev/pandas-stubs#1432 type with the correct pyarrow types
# filesystem: pyarrow.fs.FileSystem | fsspec.spec.AbstractFileSystem
filesystem: Any | None = None,
**kwargs: Any,
Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ fix = true
[tool.ruff.lint]
extend-select = ["ALL"]
ignore = [
# The following rules are ignored permanently for good reasons
"COM", # https://docs.astral.sh/ruff/rules/#flake8-commas-com
"D", # https://docs.astral.sh/ruff/rules/#pydocstyle-d
"E501", # handled by black https://docs.astral.sh/ruff/rules/line-too-long/
Expand All @@ -199,10 +200,10 @@ ignore = [
"A004", # https://docs.astral.sh/ruff/rules/builtin-import-shadowing/
"PYI001", # https://docs.astral.sh/ruff/rules/unprefixed-type-param/
"PYI042", # https://docs.astral.sh/ruff/rules/snake-case-type-alias/
"TD003", # https://docs.astral.sh/ruff/rules/missing-todo-link/
"ERA001", "ANN001", "ANN201", "ANN204", "ANN206", "ANN401", "PLR0402", "PLC0105"
]
"scripts/*" = [
# The following rules are ignored permanently for good reasons
"EM", # https://docs.astral.sh/ruff/rules/#flake8-errmsg-em
"S603", # https://docs.astral.sh/ruff/rules/subprocess-without-shell-equals-true/
]
Expand All @@ -220,7 +221,7 @@ ignore = [
"A001", # https://docs.astral.sh/ruff/rules/builtin-variable-shadowing/
"PYI042", # https://docs.astral.sh/ruff/rules/snake-case-type-alias/
"SLF001", # https://docs.astral.sh/ruff/rules/private-member-access/
"ANN001", "ANN201", "ANN204", "ANN206", "ANN401", "ARG", "ERA", "RUF", "SIM", "TRY", "PT", "NPY", "N", "DTZ", "PLR", "TC", "PGH", "PTH", "S311", "C901"
"ANN001", "ANN201", "ANN204", "ANN206", "ANN401", "ARG", "ERA", "RUF", "SIM", "TRY", "PT", "NPY", "N", "DTZ", "PLR", "TC", "PGH", "S311", "C901"
]
"tests/test_io.py" = [
# The following rules are ignored permanently for good reasons
Copy link
Member

Choose a reason for hiding this comment

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

I would probably keep the justification here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Expand Down
2 changes: 1 addition & 1 deletion tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1992,7 +1992,7 @@ def test_types_to_feather() -> None:
# See https://pandas.pydata.org/docs/whatsnew/v1.0.0.html
# Docstring and type were updated in 1.2.0.
# https://github.com/pandas-dev/pandas/pull/35408
with open(path, mode="wb") as file:
with Path(path).open("wb") as file:
df.to_feather(file)


Expand Down
Loading