Skip to content

Commit 71d53e8

Browse files
authored
feat: reduce np.ndarray (#1462)
* reduce ndarray * py310 happiness * https://github.com/pandas-dev/pandas-stubs/pull/1462/files#r2480913506 * https://github.com/pandas-dev/pandas-stubs/pull/1462/files#r2481057032 * #1462 (comment) * #1462 (comment) * #1462 (comment) * asi8 * PrettyDict * np_ndarray_bool * reduce np.double * remove np.ndarray * replace npt.NDArray with np_ndarray * comments * comments * np_xdarray_intp * unique * Indexers * remove npt.NDArray[Any] * reduce np_1darray stuff * tighten * tighten * matmul * fixup * fixup * case_when * unique * pytest * https://github.com/pandas-dev/pandas-stubs/pull/1462/files/9409ca00bff10f24c48218f3268279ec5d33cc70#r2511081138 * https://github.com/pandas-dev/pandas-stubs/pull/1462/files/9409ca00bff10f24c48218f3268279ec5d33cc70#r2510949482 * misc
1 parent a22516c commit 71d53e8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+865
-1044
lines changed

pandas-stubs/_libs/interval.pyi

Lines changed: 15 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ from typing import (
44
Literal,
55
TypeVar,
66
overload,
7+
type_check_only,
78
)
89

9-
import numpy as np
1010
from pandas import (
1111
IntervalIndex,
1212
Series,
@@ -17,8 +17,8 @@ from pandas import (
1717
from pandas._typing import (
1818
IntervalClosedType,
1919
IntervalT,
20-
np_1darray,
21-
npt,
20+
np_1darray_bool,
21+
np_ndarray,
2222
)
2323

2424
VALID_CLOSED: frozenset[str]
@@ -27,6 +27,7 @@ _OrderableScalarT = TypeVar("_OrderableScalarT", bound=int | float)
2727
_OrderableTimesT = TypeVar("_OrderableTimesT", bound=Timestamp | Timedelta)
2828
_OrderableT = TypeVar("_OrderableT", bound=int | float | Timestamp | Timedelta)
2929

30+
@type_check_only
3031
class _LengthDescriptor:
3132
@overload
3233
def __get__(
@@ -37,8 +38,9 @@ class _LengthDescriptor:
3738
self, instance: Interval[_OrderableTimesT], owner: Any
3839
) -> Timedelta: ...
3940
@overload
40-
def __get__(self, instance: IntervalTree, owner: Any) -> np.ndarray: ...
41+
def __get__(self, instance: IntervalMixin, owner: Any) -> np_ndarray: ...
4142

43+
@type_check_only
4244
class _MidDescriptor:
4345
@overload
4446
def __get__(self, instance: Interval[_OrderableScalarT], owner: Any) -> float: ...
@@ -47,7 +49,7 @@ class _MidDescriptor:
4749
self, instance: Interval[_OrderableTimesT], owner: Any
4850
) -> _OrderableTimesT: ...
4951
@overload
50-
def __get__(self, instance: IntervalTree, owner: Any) -> np.ndarray: ...
52+
def __get__(self, instance: IntervalMixin, owner: Any) -> np_ndarray: ...
5153

5254
class IntervalMixin:
5355
@property
@@ -68,8 +70,8 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
6870
def right(self: Interval[_OrderableT]) -> _OrderableT: ...
6971
@property
7072
def closed(self) -> IntervalClosedType: ...
71-
mid: _MidDescriptor
72-
length: _LengthDescriptor
73+
mid = _MidDescriptor()
74+
length = _LengthDescriptor()
7375
def __init__(
7476
self,
7577
left: _OrderableT,
@@ -166,9 +168,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
166168
@overload
167169
def __gt__(self, other: Interval[_OrderableT]) -> bool: ...
168170
@overload
169-
def __gt__(
170-
self: IntervalT, other: IntervalIndex[IntervalT]
171-
) -> np_1darray[np.bool]: ...
171+
def __gt__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_1darray_bool: ...
172172
@overload
173173
def __gt__(
174174
self,
@@ -177,9 +177,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
177177
@overload
178178
def __lt__(self, other: Interval[_OrderableT]) -> bool: ...
179179
@overload
180-
def __lt__(
181-
self: IntervalT, other: IntervalIndex[IntervalT]
182-
) -> np_1darray[np.bool]: ...
180+
def __lt__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_1darray_bool: ...
183181
@overload
184182
def __lt__(
185183
self,
@@ -188,9 +186,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
188186
@overload
189187
def __ge__(self, other: Interval[_OrderableT]) -> bool: ...
190188
@overload
191-
def __ge__(
192-
self: IntervalT, other: IntervalIndex[IntervalT]
193-
) -> np_1darray[np.bool]: ...
189+
def __ge__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_1darray_bool: ...
194190
@overload
195191
def __ge__(
196192
self,
@@ -199,45 +195,20 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
199195
@overload
200196
def __le__(self, other: Interval[_OrderableT]) -> bool: ...
201197
@overload
202-
def __le__(
203-
self: IntervalT, other: IntervalIndex[IntervalT]
204-
) -> np_1darray[np.bool]: ...
198+
def __le__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_1darray_bool: ...
205199
@overload
206200
def __eq__(self, other: Interval[_OrderableT]) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
207201
@overload
208-
def __eq__(
209-
self: IntervalT, other: IntervalIndex[IntervalT]
210-
) -> np_1darray[np.bool]: ...
202+
def __eq__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_1darray_bool: ...
211203
@overload
212204
def __eq__(self, other: Series[_OrderableT]) -> Series[bool]: ... # type: ignore[overload-overlap]
213205
@overload
214206
def __eq__(self, other: object) -> Literal[False]: ...
215207
@overload
216208
def __ne__(self, other: Interval[_OrderableT]) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
217209
@overload
218-
def __ne__(
219-
self: IntervalT, other: IntervalIndex[IntervalT]
220-
) -> np_1darray[np.bool]: ...
210+
def __ne__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_1darray_bool: ...
221211
@overload
222212
def __ne__(self, other: Series[_OrderableT]) -> Series[bool]: ... # type: ignore[overload-overlap]
223213
@overload
224214
def __ne__(self, other: object) -> Literal[True]: ...
225-
226-
class IntervalTree(IntervalMixin):
227-
def __init__(
228-
self,
229-
left: np.ndarray,
230-
right: np.ndarray,
231-
closed: IntervalClosedType = ...,
232-
leaf_size: int = ...,
233-
) -> None: ...
234-
def get_indexer(self, target) -> npt.NDArray[np.intp]: ...
235-
def get_indexer_non_unique(
236-
self, target
237-
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
238-
_na_count: int
239-
@property
240-
def is_overlapping(self) -> bool: ...
241-
@property
242-
def is_monotonic_increasing(self) -> bool: ...
243-
def clear_mapping(self) -> None: ...

pandas-stubs/_libs/tslibs/offsets.pyi

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ from typing import (
1414

1515
from dateutil.relativedelta import weekday as WeekdayClass
1616
import numpy as np
17+
from numpy import typing as npt
1718
from pandas import Timestamp
1819
from typing_extensions import Self
1920

20-
from pandas._typing import npt
21+
from pandas._typing import (
22+
ShapeT,
23+
np_ndarray,
24+
)
2125

2226
from pandas.tseries.holiday import AbstractHolidayCalendar
2327

@@ -37,7 +41,9 @@ class BaseOffset:
3741
@property
3842
def base(self) -> BaseOffset: ...
3943
@overload
40-
def __add__(self, other: npt.NDArray[np.object_]) -> npt.NDArray[np.object_]: ...
44+
def __add__(
45+
self, other: np_ndarray[ShapeT, np.object_]
46+
) -> np_ndarray[ShapeT, np.object_]: ...
4147
@overload
4248
def __add__(self, other: _DatetimeT) -> _DatetimeT: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
4349
@overload
@@ -47,7 +53,9 @@ class BaseOffset:
4753
@overload
4854
def __add__(self, other: _TimedeltaT) -> _TimedeltaT: ...
4955
@overload
50-
def __radd__(self, other: npt.NDArray[np.object_]) -> npt.NDArray[np.object_]: ...
56+
def __radd__(
57+
self, other: np_ndarray[ShapeT, np.object_]
58+
) -> np_ndarray[ShapeT, np.object_]: ...
5159
@overload
5260
def __radd__(self, other: _DatetimeT) -> _DatetimeT: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
5361
@overload
@@ -68,11 +76,15 @@ class BaseOffset:
6876
@overload
6977
def __rsub__(self, other: _TimedeltaT) -> _TimedeltaT: ...
7078
@overload
71-
def __mul__(self, other: np.ndarray) -> np.ndarray: ...
79+
def __mul__(
80+
self, other: np_ndarray[ShapeT, np.object_]
81+
) -> np_ndarray[ShapeT, np.object_]: ...
7282
@overload
7383
def __mul__(self, other: int) -> Self: ...
7484
@overload
75-
def __rmul__(self, other: np.ndarray) -> np.ndarray: ...
85+
def __rmul__(
86+
self, other: np_ndarray[ShapeT, np.object_]
87+
) -> np_ndarray[ShapeT, np.object_]: ...
7688
@overload
7789
def __rmul__(self, other: int) -> Self: ...
7890
def __neg__(self) -> Self: ...

pandas-stubs/_libs/tslibs/period.pyi

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ from pandas._libs.tslibs.timestamps import Timestamp
2020
from pandas._typing import (
2121
PeriodFrequency,
2222
ShapeT,
23-
np_1darray,
23+
np_1darray_bool,
2424
np_ndarray,
2525
)
2626

@@ -107,7 +107,7 @@ class Period(PeriodMixin):
107107
@overload
108108
def __eq__(self, other: Self) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
109109
@overload
110-
def __eq__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
110+
def __eq__(self, other: Index) -> np_1darray_bool: ... # type: ignore[overload-overlap]
111111
@overload
112112
def __eq__(self, other: Series[Period]) -> Series[bool]: ... # type: ignore[overload-overlap]
113113
@overload
@@ -117,7 +117,7 @@ class Period(PeriodMixin):
117117
@overload
118118
def __ge__(self, other: Self) -> bool: ...
119119
@overload
120-
def __ge__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
120+
def __ge__(self, other: PeriodIndex) -> np_1darray_bool: ...
121121
@overload
122122
def __ge__(
123123
self, other: Series[Period] # pyrefly: ignore[bad-specialization]
@@ -129,7 +129,7 @@ class Period(PeriodMixin):
129129
@overload
130130
def __gt__(self, other: Self) -> bool: ...
131131
@overload
132-
def __gt__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
132+
def __gt__(self, other: PeriodIndex) -> np_1darray_bool: ...
133133
@overload
134134
def __gt__(
135135
self, other: Series[Period] # pyrefly: ignore[bad-specialization]
@@ -141,7 +141,7 @@ class Period(PeriodMixin):
141141
@overload
142142
def __le__(self, other: Self) -> bool: ...
143143
@overload
144-
def __le__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
144+
def __le__(self, other: PeriodIndex) -> np_1darray_bool: ...
145145
@overload
146146
def __le__(
147147
self, other: Series[Period] # pyrefly: ignore[bad-specialization]
@@ -153,7 +153,7 @@ class Period(PeriodMixin):
153153
@overload
154154
def __lt__(self, other: Self) -> bool: ...
155155
@overload
156-
def __lt__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
156+
def __lt__(self, other: PeriodIndex) -> np_1darray_bool: ...
157157
@overload
158158
def __lt__(
159159
self, other: Series[Period] # pyrefly: ignore[bad-specialization]
@@ -167,7 +167,7 @@ class Period(PeriodMixin):
167167
@overload
168168
def __ne__(self, other: Self) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
169169
@overload
170-
def __ne__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
170+
def __ne__(self, other: Index) -> np_1darray_bool: ... # type: ignore[overload-overlap]
171171
@overload
172172
def __ne__(self, other: Series[Period]) -> Series[bool]: ... # type: ignore[overload-overlap]
173173
@overload

pandas-stubs/_libs/tslibs/timedeltas.pyi

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ from pandas._typing import (
2929
Just,
3030
ShapeT,
3131
TimeUnit,
32-
np_1darray,
32+
np_1darray_bool,
3333
np_ndarray,
3434
)
3535

@@ -274,7 +274,7 @@ class Timedelta(timedelta):
274274
@overload
275275
def __eq__(self, other: Series[Timedelta]) -> Series[bool]: ... # type: ignore[overload-overlap]
276276
@overload
277-
def __eq__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
277+
def __eq__(self, other: Index) -> np_1darray_bool: ... # type: ignore[overload-overlap]
278278
@overload
279279
def __eq__( # type: ignore[overload-overlap]
280280
self, other: np_ndarray[ShapeT, np.timedelta64]
@@ -287,7 +287,7 @@ class Timedelta(timedelta):
287287
@overload
288288
def __ne__(self, other: Series[Timedelta]) -> Series[bool]: ... # type: ignore[overload-overlap]
289289
@overload
290-
def __ne__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
290+
def __ne__(self, other: Index) -> np_1darray_bool: ... # type: ignore[overload-overlap]
291291
@overload
292292
def __ne__( # type: ignore[overload-overlap]
293293
self, other: np_ndarray[ShapeT, np.timedelta64]
@@ -316,7 +316,7 @@ class Timedelta(timedelta):
316316
@overload # type: ignore[override]
317317
def __le__(self, other: timedelta | np.timedelta64 | Self) -> bool: ...
318318
@overload
319-
def __le__(self, other: TimedeltaIndex) -> np_1darray[np.bool]: ...
319+
def __le__(self, other: TimedeltaIndex) -> np_1darray_bool: ...
320320
@overload
321321
def __le__(
322322
self, other: np_ndarray[ShapeT, np.timedelta64]
@@ -327,7 +327,7 @@ class Timedelta(timedelta):
327327
@overload # type: ignore[override]
328328
def __lt__(self, other: timedelta | np.timedelta64 | Self) -> bool: ...
329329
@overload
330-
def __lt__(self, other: TimedeltaIndex) -> np_1darray[np.bool]: ...
330+
def __lt__(self, other: TimedeltaIndex) -> np_1darray_bool: ...
331331
@overload
332332
def __lt__(
333333
self, other: np_ndarray[ShapeT, np.timedelta64]
@@ -338,7 +338,7 @@ class Timedelta(timedelta):
338338
@overload # type: ignore[override]
339339
def __ge__(self, other: timedelta | np.timedelta64 | Self) -> bool: ...
340340
@overload
341-
def __ge__(self, other: TimedeltaIndex) -> np_1darray[np.bool]: ...
341+
def __ge__(self, other: TimedeltaIndex) -> np_1darray_bool: ...
342342
@overload
343343
def __ge__(
344344
self, other: np_ndarray[ShapeT, np.timedelta64]
@@ -349,7 +349,7 @@ class Timedelta(timedelta):
349349
@overload # type: ignore[override]
350350
def __gt__(self, other: timedelta | np.timedelta64 | Self) -> bool: ...
351351
@overload
352-
def __gt__(self, other: TimedeltaIndex) -> np_1darray[np.bool]: ...
352+
def __gt__(self, other: TimedeltaIndex) -> np_1darray_bool: ...
353353
@overload
354354
def __gt__(
355355
self, other: np_ndarray[ShapeT, np.timedelta64]

pandas-stubs/_libs/tslibs/timestamps.pyi

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ from pandas._typing import (
3737
ShapeT,
3838
TimestampNonexistent,
3939
TimeUnit,
40-
np_1darray,
40+
np_1darray_bool,
4141
np_ndarray,
4242
)
4343

@@ -174,7 +174,7 @@ class Timestamp(datetime, SupportsIndex):
174174
@overload # type: ignore[override]
175175
def __le__(self, other: datetime | np.datetime64 | Self) -> bool: ...
176176
@overload
177-
def __le__(self, other: DatetimeIndex) -> np_1darray[np.bool]: ...
177+
def __le__(self, other: DatetimeIndex) -> np_1darray_bool: ...
178178
@overload
179179
def __le__(
180180
self, other: np_ndarray[ShapeT, np.datetime64]
@@ -184,7 +184,7 @@ class Timestamp(datetime, SupportsIndex):
184184
@overload # type: ignore[override]
185185
def __lt__(self, other: datetime | np.datetime64 | Self) -> bool: ...
186186
@overload
187-
def __lt__(self, other: DatetimeIndex) -> np_1darray[np.bool]: ...
187+
def __lt__(self, other: DatetimeIndex) -> np_1darray_bool: ...
188188
@overload
189189
def __lt__(
190190
self, other: np_ndarray[ShapeT, np.datetime64]
@@ -194,7 +194,7 @@ class Timestamp(datetime, SupportsIndex):
194194
@overload # type: ignore[override]
195195
def __ge__(self, other: datetime | np.datetime64 | Self) -> bool: ...
196196
@overload
197-
def __ge__(self, other: DatetimeIndex) -> np_1darray[np.bool]: ...
197+
def __ge__(self, other: DatetimeIndex) -> np_1darray_bool: ...
198198
@overload
199199
def __ge__(
200200
self, other: np_ndarray[ShapeT, np.datetime64]
@@ -204,7 +204,7 @@ class Timestamp(datetime, SupportsIndex):
204204
@overload # type: ignore[override]
205205
def __gt__(self, other: datetime | np.datetime64 | Self) -> bool: ...
206206
@overload
207-
def __gt__(self, other: DatetimeIndex) -> np_1darray[np.bool]: ...
207+
def __gt__(self, other: DatetimeIndex) -> np_1darray_bool: ...
208208
@overload
209209
def __gt__(
210210
self, other: np_ndarray[ShapeT, np.datetime64]
@@ -244,7 +244,7 @@ class Timestamp(datetime, SupportsIndex):
244244
@overload
245245
def __eq__(self, other: Series[Timestamp]) -> Series[bool]: ... # type: ignore[overload-overlap]
246246
@overload
247-
def __eq__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
247+
def __eq__(self, other: Index) -> np_1darray_bool: ... # type: ignore[overload-overlap]
248248
@overload
249249
def __eq__(self, other: np_ndarray[ShapeT, np.datetime64]) -> np_ndarray[ShapeT, np.bool]: ... # type: ignore[overload-overlap]
250250
@overload
@@ -254,7 +254,7 @@ class Timestamp(datetime, SupportsIndex):
254254
@overload
255255
def __ne__(self, other: Series[Timestamp]) -> Series[bool]: ... # type: ignore[overload-overlap]
256256
@overload
257-
def __ne__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
257+
def __ne__(self, other: Index) -> np_1darray_bool: ... # type: ignore[overload-overlap]
258258
@overload
259259
def __ne__(self, other: np_ndarray[ShapeT, np.datetime64]) -> np_ndarray[ShapeT, np.bool]: ... # type: ignore[overload-overlap]
260260
@overload

0 commit comments

Comments
 (0)