Skip to content

Commit 7c44295

Browse files
committed
refactor: drop IntervalSeries
1 parent b197a8b commit 7c44295

File tree

10 files changed

+218
-101
lines changed

10 files changed

+218
-101
lines changed

pandas-stubs/core/base.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ from collections.abc import (
55
)
66
from typing import (
77
Any,
8+
ClassVar,
89
Generic,
910
Literal,
1011
TypeAlias,
@@ -20,6 +21,7 @@ from pandas import (
2021
from pandas.core.arraylike import OpsMixin
2122
from pandas.core.arrays import ExtensionArray
2223
from pandas.core.arrays.categorical import Categorical
24+
from pandas.core.indexes.accessors import ArrayDescriptor
2325
from typing_extensions import Self
2426

2527
from pandas._typing import (
@@ -69,8 +71,7 @@ class IndexOpsMixin(OpsMixin, Generic[S1, GenericT_co]):
6971
def nbytes(self) -> int: ...
7072
@property
7173
def size(self) -> int: ...
72-
@property
73-
def array(self) -> ExtensionArray: ...
74+
array: ClassVar = ArrayDescriptor() # noqa
7475
@overload
7576
def to_numpy(
7677
self,

pandas-stubs/core/indexes/accessors.pyi

Lines changed: 46 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import datetime as dt
21
from datetime import (
2+
date,
3+
time,
34
timedelta,
45
tzinfo as _tzinfo,
56
)
67
from typing import (
7-
Any,
88
Generic,
99
Literal,
1010
TypeVar,
1111
overload,
12+
type_check_only,
1213
)
1314

1415
import numpy as np
@@ -25,18 +26,24 @@ from pandas.core.arrays import (
2526
DatetimeArray,
2627
PeriodArray,
2728
)
28-
from pandas.core.base import NoNewAttributesMixin
29+
from pandas.core.arrays.base import ExtensionArray
30+
from pandas.core.arrays.categorical import Categorical
31+
from pandas.core.arrays.interval import IntervalArray
32+
from pandas.core.arrays.timedeltas import TimedeltaArray
33+
from pandas.core.base import (
34+
IndexOpsMixin,
35+
NoNewAttributesMixin,
36+
)
2937
from pandas.core.frame import DataFrame
3038
from pandas.core.series import (
3139
PeriodSeries,
3240
Series,
3341
)
34-
from typing_extensions import Never
3542

43+
from pandas._libs.interval import Interval
3644
from pandas._libs.tslibs import BaseOffset
3745
from pandas._libs.tslibs.offsets import DateOffset
3846
from pandas._typing import (
39-
S1,
4047
TimeAmbiguous,
4148
TimeNonexistent,
4249
TimestampConvention,
@@ -46,6 +53,8 @@ from pandas._typing import (
4653
np_ndarray_bool,
4754
)
4855

56+
from pandas.core.dtypes.dtypes import CategoricalDtype
57+
4958
class Properties(PandasDelegate, NoNewAttributesMixin): ...
5059

5160
_DTFieldOpsReturnType = TypeVar("_DTFieldOpsReturnType", bound=Series[int] | Index[int])
@@ -129,10 +138,10 @@ class _DatetimeObjectOps(
129138
): ...
130139

131140
_DTOtherOpsDateReturnType = TypeVar(
132-
"_DTOtherOpsDateReturnType", bound=Series[dt.date] | np_1darray[np.object_]
141+
"_DTOtherOpsDateReturnType", bound=Series[date] | np_1darray[np.object_]
133142
)
134143
_DTOtherOpsTimeReturnType = TypeVar(
135-
"_DTOtherOpsTimeReturnType", bound=Series[dt.time] | np_1darray[np.object_]
144+
"_DTOtherOpsTimeReturnType", bound=Series[time] | np_1darray[np.object_]
136145
)
137146

138147
class _DatetimeOtherOps(Generic[_DTOtherOpsDateReturnType, _DTOtherOpsTimeReturnType]):
@@ -380,8 +389,8 @@ class CombinedDatetimelikeProperties(
380389
Series[int],
381390
Series[bool],
382391
Series,
383-
Series[dt.date],
384-
Series[dt.time],
392+
Series[date],
393+
Series[time],
385394
str,
386395
Series[Timestamp],
387396
Series[str],
@@ -395,8 +404,8 @@ class TimestampProperties(
395404
Series[int],
396405
Series[bool],
397406
Series[Timestamp],
398-
Series[dt.date],
399-
Series[dt.time],
407+
Series[date],
408+
Series[time],
400409
str,
401410
Series[Timestamp],
402411
Series[str],
@@ -434,49 +443,37 @@ class TimedeltaIndexProperties(
434443
_DatetimeRoundingMethods[TimedeltaIndex],
435444
): ...
436445

437-
class _dtDescriptor(CombinedDatetimelikeProperties, Generic[S1]):
438-
@overload
439-
def __get__(self, instance: Series[Never], owner: Any) -> Never: ...
446+
@type_check_only
447+
class DtDescriptor:
440448
@overload
441449
def __get__(
442-
self, instance: Series[Timestamp], owner: Any
450+
self, instance: Series[Timestamp], owner: type[Series]
443451
) -> TimestampProperties: ...
444452
@overload
445453
def __get__(
446-
self, instance: Series[Timedelta], owner: Any
454+
self, instance: Series[Timedelta], owner: type[Series]
447455
) -> TimedeltaProperties: ...
456+
457+
@type_check_only
458+
class ArrayDescriptor:
448459
@overload
449460
def __get__(
450-
self, instance: Series[S1], owner: Any
451-
) -> CombinedDatetimelikeProperties: ...
452-
def round(
453-
self,
454-
freq: str | BaseOffset | None,
455-
ambiguous: Literal["raise", "infer", "NaT"] | bool | np_ndarray_bool = ...,
456-
nonexistent: (
457-
Literal["shift_forward", "shift_backward", "NaT", "raise"]
458-
| timedelta
459-
| Timedelta
460-
) = ...,
461-
) -> Series[S1]: ...
462-
def floor(
463-
self,
464-
freq: str | BaseOffset | None,
465-
ambiguous: Literal["raise", "infer", "NaT"] | bool | np_ndarray_bool = ...,
466-
nonexistent: (
467-
Literal["shift_forward", "shift_backward", "NaT", "raise"]
468-
| timedelta
469-
| Timedelta
470-
) = ...,
471-
) -> Series[S1]: ...
472-
def ceil(
473-
self,
474-
freq: str | BaseOffset | None,
475-
ambiguous: Literal["raise", "infer", "NaT"] | bool | np_ndarray_bool = ...,
476-
nonexistent: (
477-
Literal["shift_forward", "shift_backward", "NaT", "raise"]
478-
| timedelta
479-
| Timedelta
480-
) = ...,
481-
) -> Series[S1]: ...
482-
def as_unit(self, unit: TimeUnit) -> Series[S1]: ...
461+
self, instance: IndexOpsMixin[CategoricalDtype], owner: type[IndexOpsMixin]
462+
) -> Categorical: ...
463+
@overload
464+
def __get__(
465+
self, instance: IndexOpsMixin[Interval], owner: type[IndexOpsMixin]
466+
) -> IntervalArray: ...
467+
@overload
468+
def __get__(
469+
self, instance: IndexOpsMixin[Timestamp], owner: type[IndexOpsMixin]
470+
) -> DatetimeArray: ...
471+
@overload
472+
def __get__(
473+
self, instance: IndexOpsMixin[Timedelta], owner: type[IndexOpsMixin]
474+
) -> TimedeltaArray: ...
475+
# should be NumpyExtensionArray
476+
@overload
477+
def __get__(
478+
self, instance: IndexOpsMixin, owner: type[IndexOpsMixin]
479+
) -> ExtensionArray: ...

pandas-stubs/core/indexes/base.pyi

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ from pandas import (
3636
Series,
3737
TimedeltaIndex,
3838
)
39-
from pandas.core.arrays import ExtensionArray
4039
from pandas.core.base import (
4140
IndexOpsMixin,
4241
NumListLike,
@@ -324,7 +323,7 @@ class Index(IndexOpsMixin[S1]):
324323
self, name: bool = ..., formatter: Callable | None = ..., na_rep: _str = ...
325324
) -> list[_str]: ...
326325
def to_flat_index(self): ...
327-
def to_series(self, index=..., name: Hashable = ...) -> Series: ...
326+
def to_series(self, index=..., name: Hashable = ...) -> Series[S1]: ...
328327
def to_frame(self, index: bool = True, name=...) -> DataFrame: ...
329328
@property
330329
def name(self) -> Hashable | None: ...
@@ -413,8 +412,6 @@ class Index(IndexOpsMixin[S1]):
413412
): ...
414413
@property
415414
def values(self) -> np_1darray: ...
416-
@property
417-
def array(self) -> ExtensionArray: ...
418415
def memory_usage(self, deep: bool = False): ...
419416
def where(self, cond, other: Scalar | ArrayLike | None = None): ...
420417
def __contains__(self, key) -> bool: ...

pandas-stubs/core/indexes/datetimes.pyi

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ from pandas import (
2020
TimedeltaIndex,
2121
Timestamp,
2222
)
23-
from pandas.core.arrays import DatetimeArray
2423
from pandas.core.indexes.accessors import DatetimeIndexProperties
2524
from pandas.core.indexes.datetimelike import DatetimeTimedeltaMixin
2625
from pandas.core.series import Series
@@ -60,10 +59,6 @@ class DatetimeIndex(
6059
) -> Self: ...
6160
def __reduce__(self): ...
6261

63-
# Override the array property to return DatetimeArray instead of ExtensionArray
64-
@property
65-
def array(self) -> DatetimeArray: ...
66-
6762
# various ignores needed for mypy, as we do want to restrict what can be used in
6863
# arithmetic for these types
6964
def __add__( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]

pandas-stubs/core/indexes/period.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ from pandas import Index
1111
from pandas.core.indexes.accessors import PeriodIndexFieldOps
1212
from pandas.core.indexes.datetimelike import DatetimeIndexOpsMixin
1313
from pandas.core.indexes.timedeltas import TimedeltaIndex
14+
from pandas.core.series import PeriodSeries
1415
from typing_extensions import Self
1516

1617
from pandas._libs.tslibs import (
@@ -74,6 +75,7 @@ class PeriodIndex(DatetimeIndexOpsMixin[pd.Period, np.object_], PeriodIndexField
7475
@property
7576
def freqstr(self) -> str: ...
7677
def shift(self, periods: int = 1, freq: Frequency | None = None) -> Self: ...
78+
def to_series(self, index=..., name: Hashable = ...) -> PeriodSeries: ...
7779

7880
def period_range(
7981
start: (

pandas-stubs/core/series.pyi

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,9 @@ from pandas.core.api import (
5555
Int32Dtype as Int32Dtype,
5656
Int64Dtype as Int64Dtype,
5757
)
58-
from pandas.core.arrays import TimedeltaArray
59-
from pandas.core.arrays.base import ExtensionArray
6058
from pandas.core.arrays.categorical import CategoricalAccessor
6159
from pandas.core.arrays.datetimes import DatetimeArray
62-
from pandas.core.arrays.interval import IntervalArray
60+
from pandas.core.arrays.timedeltas import TimedeltaArray
6361
from pandas.core.base import (
6462
IndexOpsMixin,
6563
NumListLike,
@@ -71,8 +69,8 @@ from pandas.core.groupby.generic import SeriesGroupBy
7169
from pandas.core.groupby.groupby import BaseGroupBy
7270
from pandas.core.indexers import BaseIndexer
7371
from pandas.core.indexes.accessors import (
72+
DtDescriptor,
7473
PeriodProperties,
75-
_dtDescriptor,
7674
)
7775
from pandas.core.indexes.category import CategoricalIndex
7876
from pandas.core.indexes.datetimes import DatetimeIndex
@@ -392,7 +390,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
392390
dtype: Literal["Interval"] = ...,
393391
name: Hashable = ...,
394392
copy: bool = ...,
395-
) -> IntervalSeries[_OrderableT]: ...
393+
) -> Series[Interval[_OrderableT]]: ...
396394
@overload
397395
def __new__( # type: ignore[overload-overlap]
398396
cls,
@@ -479,8 +477,6 @@ class Series(IndexOpsMixin[S1], NDFrame):
479477
def name(self, value: Hashable | None) -> None: ...
480478
@property
481479
def values(self) -> ArrayLike: ...
482-
@property
483-
def array(self) -> ExtensionArray: ...
484480
def ravel(self, order: _str = ...) -> np.ndarray: ...
485481
def __len__(self) -> int: ...
486482
def view(self, dtype=...) -> Series[S1]: ...
@@ -841,11 +837,10 @@ class Series(IndexOpsMixin[S1], NDFrame):
841837
@overload
842838
def diff(self: Series[complex], periods: int = ...) -> Series[complex]: ... # type: ignore[overload-overlap]
843839
@overload
844-
def diff(self: Series[bytes], periods: int = ...) -> Never: ...
845-
@overload
846-
def diff(self: Series[type], periods: int = ...) -> Never: ...
847-
@overload
848-
def diff(self: Series[_str], periods: int = ...) -> Never: ...
840+
def diff(
841+
self: Series[bytes] | Series[type] | Series[_str] | Series[Interval],
842+
periods: int = ...,
843+
) -> Never: ...
849844
@overload
850845
def diff(self: Series[Timestamp], periods: int = ...) -> Series[Timedelta]: ... # type: ignore[overload-overlap]
851846
@overload
@@ -1234,8 +1229,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
12341229
Series[_str],
12351230
Series,
12361231
]: ...
1237-
@property
1238-
def dt(self) -> _dtDescriptor[S1]: ...
1232+
dt: ClassVar = DtDescriptor() # noqa
12391233
@property
12401234
def plot(self) -> PlotAccessor: ...
12411235
sparse = ...
@@ -4211,9 +4205,6 @@ class Series(IndexOpsMixin[S1], NDFrame):
42114205
def __xor__(self, other: int | np_ndarray_anyint | Series[int]) -> Series[int]: ...
42124206
@final
42134207
def __invert__(self) -> Series[bool]: ...
4214-
# properties
4215-
# @property
4216-
# def array(self) -> _npndarray
42174208
@property
42184209
def at(self) -> _AtIndexer: ...
42194210
@property
@@ -4593,7 +4584,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
45934584
@overload # type: ignore[override]
45944585
def to_numpy( # pyrefly: ignore[bad-override]
45954586
self: Series[Timestamp],
4596-
dtype: None | type[np.datetime64] = None,
4587+
dtype: type[np.datetime64] | None = None,
45974588
copy: bool = False,
45984589
na_value: Scalar = ...,
45994590
**kwargs,
@@ -4609,7 +4600,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
46094600
@overload
46104601
def to_numpy( # pyrefly: ignore[bad-override]
46114602
self: Series[Timedelta],
4612-
dtype: None | type[np.timedelta64] = None,
4603+
dtype: type[np.timedelta64] | None = None,
46134604
copy: bool = False,
46144605
na_value: Scalar = ...,
46154606
**kwargs,
@@ -4623,6 +4614,22 @@ class Series(IndexOpsMixin[S1], NDFrame):
46234614
**kwargs,
46244615
) -> np_1darray[GenericT]: ...
46254616
@overload
4617+
def to_numpy(
4618+
self: Series[Interval],
4619+
dtype: type[np.object_] | None = None,
4620+
copy: bool = False,
4621+
na_value: Scalar = ...,
4622+
**kwargs,
4623+
) -> np_1darray[np.object_]: ...
4624+
@overload
4625+
def to_numpy(
4626+
self: Series[Interval],
4627+
dtype: np.dtype[GenericT] | SupportsDType[GenericT] | type[GenericT],
4628+
copy: bool = False,
4629+
na_value: Scalar = ...,
4630+
**kwargs,
4631+
) -> np_1darray[GenericT]: ...
4632+
@overload
46264633
def to_numpy( # pyright: ignore[reportIncompatibleMethodOverride]
46274634
self,
46284635
dtype: DTypeLike | None = None,
@@ -4718,7 +4725,7 @@ class _SeriesSubclassBase(Series[S1], Generic[S1, GenericT_co]):
47184725

47194726
class PeriodSeries(_SeriesSubclassBase[Period, np.object_]):
47204727
@property
4721-
def dt(self) -> PeriodProperties: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
4728+
def dt(self) -> PeriodProperties: ... # type: ignore[override]
47224729
def __sub__(self, other: PeriodSeries) -> OffsetSeries: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
47234730
def diff(self, periods: int = ...) -> OffsetSeries: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
47244731

@@ -4729,10 +4736,3 @@ class OffsetSeries(_SeriesSubclassBase[BaseOffset, np.object_]):
47294736
def __radd__( # pyright: ignore[reportIncompatibleMethodOverride]
47304737
self, other: BaseOffset
47314738
) -> OffsetSeries: ...
4732-
4733-
class IntervalSeries(
4734-
_SeriesSubclassBase[Interval[_OrderableT], np.object_], Generic[_OrderableT]
4735-
):
4736-
@property
4737-
def array(self) -> IntervalArray: ...
4738-
def diff(self, periods: int = ...) -> Never: ... # pyrefly: ignore

0 commit comments

Comments
 (0)