Skip to content

Commit 350c8b2

Browse files
Merge branch 'main' of github.com:loicdiridollou/pandas-stubs into gh1383_categorical
2 parents edc6ec5 + 0042dfd commit 350c8b2

File tree

17 files changed

+369
-184
lines changed

17 files changed

+369
-184
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
@@ -97,7 +94,7 @@ class Period(PeriodMixin):
9794
def __add__(self, other: Index) -> PeriodIndex: ...
9895
@overload
9996
def __add__(
100-
self, other: OffsetSeries | Series[Timedelta]
97+
self, other: Series[BaseOffset] | Series[Timedelta]
10198
) -> Series[Period]: ... # pyrefly: ignore[bad-specialization]
10299
# ignore[misc] here because we know all other comparisons
103100
# 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,42 +1,44 @@
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.offsets import DateOffset
3738
from pandas._libs.tslibs.period import Period
39+
from pandas._libs.tslibs.timedeltas import Timedelta
40+
from pandas._libs.tslibs.timestamps import Timestamp
3841
from pandas._typing import (
39-
S1,
4042
TimeAmbiguous,
4143
TimeNonexistent,
4244
TimestampConvention,
@@ -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]):
@@ -380,8 +384,8 @@ class CombinedDatetimelikeProperties(
380384
Series[int],
381385
Series[bool],
382386
Series,
383-
Series[dt.date],
384-
Series[dt.time],
387+
Series[date],
388+
Series[time],
385389
str,
386390
Series[Timestamp],
387391
Series[str],
@@ -390,13 +394,15 @@ class CombinedDatetimelikeProperties(
390394
_TimedeltaPropertiesNoRounding[Series[int], Series[float]],
391395
_PeriodProperties,
392396
): ...
397+
398+
@type_check_only
393399
class TimestampProperties(
394400
DatetimeProperties[
395401
Series[int],
396402
Series[bool],
397403
Series[Timestamp],
398-
Series[dt.date],
399-
Series[dt.time],
404+
Series[date],
405+
Series[time],
400406
str,
401407
Series[Timestamp],
402408
Series[str],
@@ -434,51 +440,47 @@ class TimedeltaIndexProperties(
434440
_DatetimeRoundingMethods[TimedeltaIndex],
435441
): ...
436442

437-
class _dtDescriptor(CombinedDatetimelikeProperties, Generic[S1]):
438-
@overload
439-
def __get__(self, instance: Series[Never], owner: Any) -> Never: ...
443+
@type_check_only
444+
class DtDescriptor:
440445
@overload
441-
def __get__(self, instance: Series[Period], owner: Any) -> PeriodProperties: ...
446+
def __get__(self, instance: Series[Never], owner: type[Series]) -> Properties: ...
442447
@overload
443448
def __get__(
444-
self, instance: Series[Timestamp], owner: Any
449+
self, instance: Series[Timestamp], owner: type[Series]
445450
) -> TimestampProperties: ...
446451
@overload
447452
def __get__(
448-
self, instance: Series[Timedelta], owner: Any
453+
self, instance: Series[Timedelta], owner: type[Series]
449454
) -> TimedeltaProperties: ...
450455
@overload
451456
def __get__(
452-
self, instance: Series[S1], owner: Any
453-
) -> CombinedDatetimelikeProperties: ...
454-
def round(
455-
self,
456-
freq: str | BaseOffset | None,
457-
ambiguous: Literal["raise", "infer", "NaT"] | bool | np_ndarray_bool = ...,
458-
nonexistent: (
459-
Literal["shift_forward", "shift_backward", "NaT", "raise"]
460-
| timedelta
461-
| Timedelta
462-
) = ...,
463-
) -> Series[S1]: ...
464-
def floor(
465-
self,
466-
freq: str | BaseOffset | None,
467-
ambiguous: Literal["raise", "infer", "NaT"] | bool | np_ndarray_bool = ...,
468-
nonexistent: (
469-
Literal["shift_forward", "shift_backward", "NaT", "raise"]
470-
| timedelta
471-
| Timedelta
472-
) = ...,
473-
) -> Series[S1]: ...
474-
def ceil(
475-
self,
476-
freq: str | BaseOffset | None,
477-
ambiguous: Literal["raise", "infer", "NaT"] | bool | np_ndarray_bool = ...,
478-
nonexistent: (
479-
Literal["shift_forward", "shift_backward", "NaT", "raise"]
480-
| timedelta
481-
| Timedelta
482-
) = ...,
483-
) -> Series[S1]: ...
484-
def as_unit(self, unit: TimeUnit) -> Series[S1]: ...
457+
self, instance: Series[Period], owner: type[Series]
458+
) -> PeriodProperties: ...
459+
460+
@type_check_only
461+
class ArrayDescriptor:
462+
@overload
463+
def __get__(
464+
self, instance: IndexOpsMixin[Never], owner: type[IndexOpsMixin]
465+
) -> ExtensionArray: ...
466+
@overload
467+
def __get__(
468+
self, instance: IndexOpsMixin[CategoricalDtype], owner: type[IndexOpsMixin]
469+
) -> Categorical: ...
470+
@overload
471+
def __get__(
472+
self, instance: IndexOpsMixin[Interval], owner: type[IndexOpsMixin]
473+
) -> IntervalArray: ...
474+
@overload
475+
def __get__(
476+
self, instance: IndexOpsMixin[Timestamp], owner: type[IndexOpsMixin]
477+
) -> DatetimeArray: ...
478+
@overload
479+
def __get__(
480+
self, instance: IndexOpsMixin[Timedelta], owner: type[IndexOpsMixin]
481+
) -> TimedeltaArray: ...
482+
# should be NumpyExtensionArray
483+
@overload
484+
def __get__(
485+
self, instance: IndexOpsMixin, owner: type[IndexOpsMixin]
486+
) -> ExtensionArray: ...

pandas-stubs/core/indexes/base.pyi

Lines changed: 3 additions & 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,
@@ -336,7 +335,9 @@ class Index(IndexOpsMixin[S1]):
336335
self, name: bool = ..., formatter: Callable | None = ..., na_rep: _str = ...
337336
) -> list[_str]: ...
338337
def to_flat_index(self): ...
339-
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]: ...
340341
def to_frame(self, index: bool = True, name=...) -> DataFrame: ...
341342
@property
342343
def name(self) -> Hashable | None: ...
@@ -425,8 +426,6 @@ class Index(IndexOpsMixin[S1]):
425426
): ...
426427
@property
427428
def values(self) -> np_1darray: ...
428-
@property
429-
def array(self) -> ExtensionArray: ...
430429
def memory_usage(self, deep: bool = False): ...
431430
def where(self, cond, other: Scalar | ArrayLike | None = None): ...
432431
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
@@ -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]
@@ -82,10 +77,11 @@ class DatetimeIndex(
8277
self, other: datetime | np.datetime64 | np_ndarray_dt | DatetimeIndex
8378
) -> TimedeltaIndex: ...
8479
@final
85-
def to_series(self, index=..., name: Hashable = ...) -> Series[Timestamp]: ...
80+
def to_series(
81+
self, index: Index | None = None, name: Hashable | None = None
82+
) -> Series[Timestamp]: ...
8683
def snap(self, freq: str = ...): ...
8784
def slice_indexer(self, start=..., end=..., step=...): ...
88-
def searchsorted(self, value, side: str = ..., sorter=...): ...
8985
@property
9086
def inferred_type(self) -> str: ...
9187
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
@@ -81,11 +81,12 @@ class TimedeltaIndex(
8181
self, other: dt.timedelta | Sequence[dt.timedelta]
8282
) -> Index[int]: ...
8383
def __rfloordiv__(self, other: dt.timedelta | Sequence[dt.timedelta]) -> Index[int]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
84-
def searchsorted(self, value, side: str = ..., sorter=...): ...
8584
@property
8685
def inferred_type(self) -> str: ...
8786
@final
88-
def to_series(self, index=..., name: Hashable = ...) -> Series[Timedelta]: ...
87+
def to_series(
88+
self, index: Index | None = None, name: Hashable | None = None
89+
) -> Series[Timedelta]: ...
8990
def shift(self, periods: int = 1, freq=...) -> Self: ...
9091

9192
@overload

0 commit comments

Comments
 (0)