diff --git a/pandas-stubs/_libs/interval.pyi b/pandas-stubs/_libs/interval.pyi index 82c9b751d..0dd40c964 100644 --- a/pandas-stubs/_libs/interval.pyi +++ b/pandas-stubs/_libs/interval.pyi @@ -27,9 +27,9 @@ from pandas._typing import ( VALID_CLOSED: frozenset[str] -_OrderableScalarT = TypeVar("_OrderableScalarT", int, float) -_OrderableTimesT = TypeVar("_OrderableTimesT", Timestamp, Timedelta) -_OrderableT = TypeVar("_OrderableT", int, float, Timestamp, Timedelta) +_OrderableScalarT = TypeVar("_OrderableScalarT", bound=int | float) +_OrderableTimesT = TypeVar("_OrderableTimesT", bound=Timestamp | Timedelta) +_OrderableT = TypeVar("_OrderableT", bound=int | float | Timestamp | Timedelta) class _LengthDescriptor: @overload diff --git a/pandas-stubs/_typing.pyi b/pandas-stubs/_typing.pyi index 673a50446..106ada7b0 100644 --- a/pandas-stubs/_typing.pyi +++ b/pandas-stubs/_typing.pyi @@ -360,13 +360,7 @@ NDFrameT = TypeVar("NDFrameT", bound=NDFrame) IndexT = TypeVar("IndexT", bound=Index) # Interval closed type -IntervalT = TypeVar( - "IntervalT", - Interval[int], - Interval[float], - Interval[Timestamp], - Interval[Timedelta], -) +IntervalT = TypeVar("IntervalT", bound=Interval) IntervalClosedType: TypeAlias = Literal["left", "right", "both", "neither"] TakeIndexer: TypeAlias = Sequence[int] | Sequence[np.integer] | npt.NDArray[np.integer] diff --git a/pandas-stubs/core/series.pyi b/pandas-stubs/core/series.pyi index 032ff40a3..ae6daa5da 100644 --- a/pandas-stubs/core/series.pyi +++ b/pandas-stubs/core/series.pyi @@ -27,6 +27,7 @@ from matplotlib.axes import ( import numpy as np from pandas import ( Period, + PeriodDtype, Timedelta, Timestamp, ) @@ -104,6 +105,7 @@ from pandas._typing import ( CategoryDtypeArg, ComplexDtypeArg, CompressionOptions, + Dtype, DtypeBackend, DtypeObj, FilePath, @@ -209,92 +211,55 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]): _ListLike: TypeAlias = ArrayLike | dict[_str, np.ndarray] | list | tuple | Index __hash__: ClassVar[None] + # TODO: can __new__ be converted to __init__? Pandas implements __init__ @overload def __new__( cls, data: DatetimeIndex | Sequence[Timestamp | np.datetime64 | datetime], index: Axes | None = ..., - dtype=..., + dtype: TimestampDtypeArg = ..., name: Hashable | None = ..., copy: bool = ..., - fastpath: bool = ..., ) -> TimestampSeries: ... @overload def __new__( cls, data: _ListLike, - dtype: Literal["datetime64[ns]"], index: Axes | None = ..., + *, + dtype: TimestampDtypeArg, name: Hashable | None = ..., copy: bool = ..., - fastpath: bool = ..., ) -> TimestampSeries: ... @overload def __new__( cls, data: PeriodIndex, index: Axes | None = ..., - dtype=..., + dtype: PeriodDtype = ..., name: Hashable | None = ..., copy: bool = ..., - fastpath: bool = ..., ) -> PeriodSeries: ... @overload def __new__( cls, data: TimedeltaIndex | Sequence[Timedelta | np.timedelta64 | timedelta], index: Axes | None = ..., - dtype=..., + dtype: TimedeltaDtypeArg = ..., name: Hashable | None = ..., copy: bool = ..., - fastpath: bool = ..., ) -> TimedeltaSeries: ... @overload def __new__( cls, - data: IntervalIndex[Interval[int]] | Interval[int] | Sequence[Interval[int]], - index: Axes | None = ..., - dtype=..., - name: Hashable | None = ..., - copy: bool = ..., - fastpath: bool = ..., - ) -> IntervalSeries[int]: ... - @overload - def __new__( - cls, - data: IntervalIndex[Interval[float]] - | Interval[float] - | Sequence[Interval[float]], - index: Axes | None = ..., - dtype=..., - name: Hashable | None = ..., - copy: bool = ..., - fastpath: bool = ..., - ) -> IntervalSeries[float]: ... - @overload - def __new__( - cls, - data: IntervalIndex[Interval[Timestamp]] - | Interval[Timestamp] - | Sequence[Interval[Timestamp]], - index: Axes | None = ..., - dtype=..., - name: Hashable | None = ..., - copy: bool = ..., - fastpath: bool = ..., - ) -> IntervalSeries[Timestamp]: ... - @overload - def __new__( - cls, - data: IntervalIndex[Interval[Timedelta]] - | Interval[Timedelta] - | Sequence[Interval[Timedelta]], + data: IntervalIndex[Interval[_OrderableT]] + | Interval[_OrderableT] + | Sequence[Interval[_OrderableT]], index: Axes | None = ..., - dtype=..., + dtype: Literal["Interval"] = ..., name: Hashable | None = ..., copy: bool = ..., - fastpath: bool = ..., - ) -> IntervalSeries[Timedelta]: ... + ) -> IntervalSeries[_OrderableT]: ... @overload def __new__( cls, @@ -303,27 +268,24 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]): index: Axes | None = ..., name: Hashable | None = ..., copy: bool = ..., - fastpath: bool = ..., ) -> Self: ... @overload def __new__( cls, data: Series[S1] | dict[int, S1] | dict[_str, S1] = ..., index: Axes | None = ..., - dtype=..., + dtype: Dtype = ..., name: Hashable | None = ..., copy: bool = ..., - fastpath: bool = ..., ) -> Self: ... @overload def __new__( cls, data: object | _ListLike | None = ..., index: Axes | None = ..., - dtype=..., + dtype: Dtype = ..., name: Hashable | None = ..., copy: bool = ..., - fastpath: bool = ..., ) -> Series: ... @property def hasnans(self) -> bool: ...