Skip to content

Commit 8e2b00e

Browse files
committed
Merge remote-tracking branch 'upstream/main' into unify-freq
2 parents 8078382 + a9f0bd3 commit 8e2b00e

File tree

17 files changed

+400
-186
lines changed

17 files changed

+400
-186
lines changed

pandas-stubs/_libs/tslibs/period.pyi

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ from pandas import (
1212
Timedelta,
1313
TimedeltaIndex,
1414
)
15-
from pandas.core.series import (
16-
OffsetSeries,
17-
)
1815
from typing_extensions import TypeAlias
1916

2017
from pandas._libs.tslibs import NaTType
@@ -98,7 +95,7 @@ class Period(PeriodMixin):
9895
def __add__(self, other: Index) -> PeriodIndex: ...
9996
@overload
10097
def __add__(
101-
self, other: OffsetSeries | Series[Timedelta]
98+
self, other: Series[BaseOffset] | Series[Timedelta]
10299
) -> Series[Period]: ... # pyrefly: ignore[bad-specialization]
103100
# ignore[misc] here because we know all other comparisons
104101
# are False, so we use Literal[False]

pandas-stubs/core/arrays/categorical.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ class Categorical(ExtensionArray):
9696
@property
9797
def nbytes(self) -> int: ...
9898
def memory_usage(self, deep: bool = ...): ...
99-
def searchsorted(self, value, side: str = ..., sorter=...): ...
10099
def isna(self) -> np_1darray[np.bool]: ...
101100
def isnull(self) -> np_1darray[np.bool]: ...
102101
def notna(self) -> np_1darray[np.bool]: ...

pandas-stubs/core/arrays/datetimelike.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ class DatetimeLikeArrayMixin(ExtensionOpsMixin, ExtensionArray):
8484
def unique(self): ...
8585
def copy(self): ...
8686
def shift(self, periods: int = 1, fill_value=..., axis: int = ...): ...
87-
def searchsorted(self, value, side: str = ..., sorter=...): ...
8887
def repeat(self, repeats, *args, **kwargs): ... # pyrefly: ignore
8988
def value_counts(self, dropna: bool = True): ...
9089
def map(self, mapper): ...

pandas-stubs/core/base.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ from pandas import (
2020
from pandas.core.arraylike import OpsMixin
2121
from pandas.core.arrays import ExtensionArray
2222
from pandas.core.arrays.categorical import Categorical
23+
from pandas.core.indexes.accessors import ArrayDescriptor
2324
from typing_extensions import Self
2425

2526
from pandas._typing import (
@@ -69,8 +70,7 @@ class IndexOpsMixin(OpsMixin, Generic[S1, GenericT_co]):
6970
def nbytes(self) -> int: ...
7071
@property
7172
def size(self) -> int: ...
72-
@property
73-
def array(self) -> ExtensionArray: ...
73+
array = ArrayDescriptor()
7474
@overload
7575
def to_numpy(
7676
self,

pandas-stubs/core/indexes/accessors.pyi

Lines changed: 65 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,43 @@
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
15-
from pandas import (
16-
DatetimeIndex,
17-
Index,
18-
PeriodIndex,
19-
Timedelta,
20-
TimedeltaIndex,
21-
Timestamp,
22-
)
2316
from pandas.core.accessor import PandasDelegate
24-
from pandas.core.arrays import (
25-
DatetimeArray,
26-
PeriodArray,
17+
from pandas.core.arrays.base import ExtensionArray
18+
from pandas.core.arrays.categorical import Categorical
19+
from pandas.core.arrays.datetimes import DatetimeArray
20+
from pandas.core.arrays.interval import IntervalArray
21+
from pandas.core.arrays.period import PeriodArray
22+
from pandas.core.arrays.timedeltas import TimedeltaArray
23+
from pandas.core.base import (
24+
IndexOpsMixin,
25+
NoNewAttributesMixin,
2726
)
28-
from pandas.core.base import NoNewAttributesMixin
2927
from pandas.core.frame import DataFrame
30-
from pandas.core.series import (
31-
Series,
32-
)
28+
from pandas.core.indexes.base import Index
29+
from pandas.core.indexes.datetimes import DatetimeIndex
30+
from pandas.core.indexes.period import PeriodIndex
31+
from pandas.core.indexes.timedeltas import TimedeltaIndex
32+
from pandas.core.series import Series
3333
from typing_extensions import Never
3434

35+
from pandas._libs.interval import Interval
3536
from pandas._libs.tslibs import BaseOffset
3637
from pandas._libs.tslibs.period import Period
38+
from pandas._libs.tslibs.timedeltas import Timedelta
39+
from pandas._libs.tslibs.timestamps import Timestamp
3740
from pandas._typing import (
38-
S1,
3941
Frequency,
4042
TimeAmbiguous,
4143
TimeNonexistent,
@@ -46,6 +48,8 @@ from pandas._typing import (
4648
np_ndarray_bool,
4749
)
4850

51+
from pandas.core.dtypes.dtypes import CategoricalDtype
52+
4953
class Properties(PandasDelegate, NoNewAttributesMixin): ...
5054

5155
_DTFieldOpsReturnType = TypeVar("_DTFieldOpsReturnType", bound=Series[int] | Index[int])
@@ -129,10 +133,10 @@ class _DatetimeObjectOps(
129133
): ...
130134

131135
_DTOtherOpsDateReturnType = TypeVar(
132-
"_DTOtherOpsDateReturnType", bound=Series[dt.date] | np_1darray[np.object_]
136+
"_DTOtherOpsDateReturnType", bound=Series[date] | np_1darray[np.object_]
133137
)
134138
_DTOtherOpsTimeReturnType = TypeVar(
135-
"_DTOtherOpsTimeReturnType", bound=Series[dt.time] | np_1darray[np.object_]
139+
"_DTOtherOpsTimeReturnType", bound=Series[time] | np_1darray[np.object_]
136140
)
137141

138142
class _DatetimeOtherOps(Generic[_DTOtherOpsDateReturnType, _DTOtherOpsTimeReturnType]):
@@ -378,8 +382,8 @@ class CombinedDatetimelikeProperties(
378382
Series[int],
379383
Series[bool],
380384
Series,
381-
Series[dt.date],
382-
Series[dt.time],
385+
Series[date],
386+
Series[time],
383387
str,
384388
Series[Timestamp],
385389
Series[str],
@@ -388,13 +392,15 @@ class CombinedDatetimelikeProperties(
388392
_TimedeltaPropertiesNoRounding[Series[int], Series[float]],
389393
_PeriodProperties,
390394
): ...
395+
396+
@type_check_only
391397
class TimestampProperties(
392398
DatetimeProperties[
393399
Series[int],
394400
Series[bool],
395401
Series[Timestamp],
396-
Series[dt.date],
397-
Series[dt.time],
402+
Series[date],
403+
Series[time],
398404
str,
399405
Series[Timestamp],
400406
Series[str],
@@ -432,51 +438,47 @@ class TimedeltaIndexProperties(
432438
_DatetimeRoundingMethods[TimedeltaIndex],
433439
): ...
434440

435-
class _dtDescriptor(CombinedDatetimelikeProperties, Generic[S1]):
436-
@overload
437-
def __get__(self, instance: Series[Never], owner: Any) -> Never: ...
441+
@type_check_only
442+
class DtDescriptor:
438443
@overload
439-
def __get__(self, instance: Series[Period], owner: Any) -> PeriodProperties: ...
444+
def __get__(self, instance: Series[Never], owner: type[Series]) -> Properties: ...
440445
@overload
441446
def __get__(
442-
self, instance: Series[Timestamp], owner: Any
447+
self, instance: Series[Timestamp], owner: type[Series]
443448
) -> TimestampProperties: ...
444449
@overload
445450
def __get__(
446-
self, instance: Series[Timedelta], owner: Any
451+
self, instance: Series[Timedelta], owner: type[Series]
447452
) -> TimedeltaProperties: ...
448453
@overload
449454
def __get__(
450-
self, instance: Series[S1], owner: Any
451-
) -> CombinedDatetimelikeProperties: ...
452-
def round(
453-
self,
454-
freq: Frequency | 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: Frequency | 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: Frequency | 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]: ...
455+
self, instance: Series[Period], owner: type[Series]
456+
) -> PeriodProperties: ...
457+
458+
@type_check_only
459+
class ArrayDescriptor:
460+
@overload
461+
def __get__(
462+
self, instance: IndexOpsMixin[Never], owner: type[IndexOpsMixin]
463+
) -> ExtensionArray: ...
464+
@overload
465+
def __get__(
466+
self, instance: IndexOpsMixin[CategoricalDtype], owner: type[IndexOpsMixin]
467+
) -> Categorical: ...
468+
@overload
469+
def __get__(
470+
self, instance: IndexOpsMixin[Interval], owner: type[IndexOpsMixin]
471+
) -> IntervalArray: ...
472+
@overload
473+
def __get__(
474+
self, instance: IndexOpsMixin[Timestamp], owner: type[IndexOpsMixin]
475+
) -> DatetimeArray: ...
476+
@overload
477+
def __get__(
478+
self, instance: IndexOpsMixin[Timedelta], owner: type[IndexOpsMixin]
479+
) -> TimedeltaArray: ...
480+
# should be NumpyExtensionArray
481+
@overload
482+
def __get__(
483+
self, instance: IndexOpsMixin, owner: type[IndexOpsMixin]
484+
) -> ExtensionArray: ...

pandas-stubs/core/indexes/base.pyi

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ 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,
4342
_ListLike,
4443
)
44+
from pandas.core.indexes.category import CategoricalIndex
4545
from pandas.core.strings.accessor import StringMethods
4646
from typing_extensions import (
4747
Never,
@@ -58,6 +58,7 @@ from pandas._typing import (
5858
AnyAll,
5959
ArrayLike,
6060
AxesData,
61+
CategoryDtypeArg,
6162
DropKeep,
6263
Dtype,
6364
DtypeArg,
@@ -229,6 +230,16 @@ class Index(IndexOpsMixin[S1]):
229230
tupleize_cols: bool = ...,
230231
) -> TimedeltaIndex: ...
231232
@overload
233+
def __new__(
234+
cls,
235+
data: AxesData,
236+
*,
237+
dtype: CategoryDtypeArg,
238+
copy: bool = ...,
239+
name: Hashable = ...,
240+
tupleize_cols: bool = ...,
241+
) -> CategoricalIndex: ...
242+
@overload
232243
def __new__(
233244
cls,
234245
data: Sequence[Interval[_OrderableT]] | IndexOpsMixin[Interval[_OrderableT]],
@@ -324,7 +335,9 @@ class Index(IndexOpsMixin[S1]):
324335
self, name: bool = ..., formatter: Callable | None = ..., na_rep: _str = ...
325336
) -> list[_str]: ...
326337
def to_flat_index(self): ...
327-
def to_series(self, index=..., name: Hashable = ...) -> Series: ...
338+
def to_series(
339+
self, index: Index | None = None, name: Hashable | None = None
340+
) -> Series[S1]: ...
328341
def to_frame(self, index: bool = True, name=...) -> DataFrame: ...
329342
@property
330343
def name(self) -> Hashable | None: ...
@@ -413,8 +426,6 @@ class Index(IndexOpsMixin[S1]):
413426
): ...
414427
@property
415428
def values(self) -> np_1darray: ...
416-
@property
417-
def array(self) -> ExtensionArray: ...
418429
def memory_usage(self, deep: bool = False): ...
419430
def where(self, cond, other: Scalar | ArrayLike | None = None): ...
420431
def __contains__(self, key) -> bool: ...

pandas-stubs/core/indexes/datetimes.pyi

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ from pandas import (
1919
TimedeltaIndex,
2020
Timestamp,
2121
)
22-
from pandas.core.arrays import DatetimeArray
2322
from pandas.core.indexes.accessors import DatetimeIndexProperties
2423
from pandas.core.indexes.datetimelike import DatetimeTimedeltaMixin
2524
from pandas.core.series import Series
@@ -58,10 +57,6 @@ class DatetimeIndex(
5857
) -> Self: ...
5958
def __reduce__(self): ...
6059

61-
# Override the array property to return DatetimeArray instead of ExtensionArray
62-
@property
63-
def array(self) -> DatetimeArray: ...
64-
6560
# various ignores needed for mypy, as we do want to restrict what can be used in
6661
# arithmetic for these types
6762
def __add__( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
@@ -80,10 +75,11 @@ class DatetimeIndex(
8075
self, other: datetime | np.datetime64 | np_ndarray_dt | DatetimeIndex
8176
) -> TimedeltaIndex: ...
8277
@final
83-
def to_series(self, index=..., name: Hashable = ...) -> Series[Timestamp]: ...
78+
def to_series(
79+
self, index: Index | None = None, name: Hashable | None = None
80+
) -> Series[Timestamp]: ...
8481
def snap(self, freq: str = ...): ...
8582
def slice_indexer(self, start=..., end=..., step=...): ...
86-
def searchsorted(self, value, side: str = ..., sorter=...): ...
8783
@property
8884
def inferred_type(self) -> str: ...
8985
def indexer_at_time(self, time, asof: bool = ...): ...

pandas-stubs/core/indexes/timedeltas.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,12 @@ class TimedeltaIndex(
8080
self, other: dt.timedelta | Sequence[dt.timedelta]
8181
) -> Index[int]: ...
8282
def __rfloordiv__(self, other: dt.timedelta | Sequence[dt.timedelta]) -> Index[int]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
83-
def searchsorted(self, value, side: str = ..., sorter=...): ...
8483
@property
8584
def inferred_type(self) -> str: ...
8685
@final
87-
def to_series(self, index=..., name: Hashable = ...) -> Series[Timedelta]: ...
86+
def to_series(
87+
self, index: Index | None = None, name: Hashable | None = None
88+
) -> Series[Timedelta]: ...
8889
def shift(
8990
self, periods: int = 1, freq: Frequency | dt.timedelta | None = None
9091
) -> Self: ...

0 commit comments

Comments
 (0)