Skip to content

Commit d779dbe

Browse files
committed
Merge branch 'main' of github.com:pandas-dev/pandas-stubs into feature/reduce-ndarray
2 parents 4070c2d + a22516c commit d779dbe

File tree

24 files changed

+2218
-703
lines changed

24 files changed

+2218
-703
lines changed

pandas-stubs/_typing.pyi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,9 @@ np_ndarray_anyint: TypeAlias = npt.NDArray[np.integer]
843843
np_ndarray_float: TypeAlias = npt.NDArray[np.floating]
844844
np_ndarray_complex: TypeAlias = npt.NDArray[np.complexfloating]
845845
np_ndarray_bool: TypeAlias = npt.NDArray[np.bool_]
846+
np_ndarray_num: TypeAlias = npt.NDArray[
847+
np.bool | np.integer | np.floating | np.complexfloating
848+
]
846849
np_ndarray_str: TypeAlias = npt.NDArray[np.str_]
847850
np_ndarray_dt: TypeAlias = npt.NDArray[np.datetime64]
848851
np_ndarray_td: TypeAlias = npt.NDArray[np.timedelta64]
@@ -1118,8 +1121,7 @@ Incomplete: TypeAlias = Any
11181121
class Just(Protocol, Generic[T]):
11191122
@property # type: ignore[override]
11201123
@override
1121-
# pyrefly: ignore # bad-override
1122-
def __class__(self, /) -> type[T]: ...
1124+
def __class__(self, /) -> type[T]: ... # pyrefly: ignore[bad-override]
11231125
@__class__.setter
11241126
@override
11251127
def __class__(self, t: type[T], /) -> None: ...

pandas-stubs/core/base.pyi

Lines changed: 116 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ from numpy import typing as npt
2121
from pandas.core.arraylike import OpsMixin
2222
from pandas.core.arrays import ExtensionArray
2323
from pandas.core.arrays.categorical import Categorical
24+
from pandas.core.arrays.integer import IntegerArray
25+
from pandas.core.arrays.timedeltas import TimedeltaArray
2426
from pandas.core.indexes.accessors import ArrayDescriptor
2527
from pandas.core.indexes.base import Index
28+
from pandas.core.indexes.timedeltas import TimedeltaIndex
2629
from pandas.core.series import Series
2730
from typing_extensions import Self
2831

@@ -45,6 +48,7 @@ from pandas._typing import (
4548
np_ndarray_bool,
4649
np_ndarray_complex,
4750
np_ndarray_float,
51+
np_ndarray_td,
4852
)
4953
from pandas.util._decorators import cache_readonly
5054

@@ -169,7 +173,84 @@ class IndexOpsMixin(OpsMixin, Generic[S1, GenericT_co]):
169173
) -> np.intp: ...
170174
def drop_duplicates(self, *, keep: DropKeep = ...) -> Self: ...
171175

172-
NumListLike: TypeAlias = (
176+
ScalarArrayIndexJustInt: TypeAlias = (
177+
Just[int]
178+
| np.integer
179+
| Sequence[Just[int] | np.integer]
180+
| np_ndarray_anyint
181+
| IntegerArray
182+
| Index[int]
183+
)
184+
ScalarArrayIndexSeriesJustInt: TypeAlias = ScalarArrayIndexJustInt | Series[int]
185+
ScalarArrayIndexJustFloat: TypeAlias = (
186+
Just[float]
187+
| np.floating
188+
| Sequence[Just[float] | np.floating]
189+
| np_ndarray_float
190+
# | FloatingArray # TODO: after pandas-dev/pandas-stubs#1469
191+
| Index[float]
192+
)
193+
ScalarArrayIndexSeriesJustFloat: TypeAlias = ScalarArrayIndexJustFloat | Series[float]
194+
ScalarArrayIndexJustComplex: TypeAlias = (
195+
Just[complex]
196+
| np.complexfloating
197+
| Sequence[Just[complex] | np.complexfloating]
198+
| np_ndarray_complex
199+
| Index[complex]
200+
)
201+
ScalarArrayIndexSeriesJustComplex: TypeAlias = (
202+
ScalarArrayIndexJustComplex | Series[complex]
203+
)
204+
205+
ScalarArrayIndexIntNoBool: TypeAlias = (
206+
Just[int]
207+
| np.integer
208+
| Sequence[int | np.integer]
209+
| np_ndarray_anyint
210+
| IntegerArray
211+
| Index[int]
212+
)
213+
ScalarArrayIndexSeriesIntNoBool: TypeAlias = ScalarArrayIndexIntNoBool | Series[int]
214+
215+
NumpyRealScalar: TypeAlias = np.bool | np.integer | np.floating
216+
IndexReal: TypeAlias = Index[bool] | Index[int] | Index[float]
217+
ScalarArrayIndexReal: TypeAlias = (
218+
float
219+
| Sequence[float | NumpyRealScalar]
220+
| NumpyRealScalar
221+
| np.typing.NDArray[NumpyRealScalar]
222+
| ExtensionArray
223+
| IndexReal
224+
)
225+
SeriesReal: TypeAlias = Series[bool] | Series[int] | Series[float]
226+
ScalarArrayIndexSeriesReal: TypeAlias = ScalarArrayIndexReal | SeriesReal
227+
228+
NumpyComplexScalar: TypeAlias = NumpyRealScalar | np.complexfloating
229+
IndexComplex: TypeAlias = IndexReal | Index[complex]
230+
ScalarArrayIndexComplex: TypeAlias = (
231+
complex
232+
| Sequence[complex | NumpyComplexScalar]
233+
| NumpyComplexScalar
234+
| np.typing.NDArray[NumpyComplexScalar]
235+
| ExtensionArray
236+
| IndexComplex
237+
)
238+
SeriesComplex: TypeAlias = SeriesReal | Series[complex]
239+
ScalarArrayIndexSeriesComplex: TypeAlias = ScalarArrayIndexComplex | SeriesComplex
240+
241+
ArrayIndexTimedeltaNoSeq: TypeAlias = np_ndarray_td | TimedeltaArray | TimedeltaIndex
242+
ScalarArrayIndexTimedelta: TypeAlias = (
243+
timedelta
244+
| np.timedelta64
245+
| Sequence[timedelta | np.timedelta64]
246+
| ArrayIndexTimedeltaNoSeq
247+
)
248+
ArrayIndexSeriesTimedeltaNoSeq: TypeAlias = ArrayIndexTimedeltaNoSeq | Series[Timedelta]
249+
ScalarArrayIndexSeriesTimedelta: TypeAlias = (
250+
ScalarArrayIndexTimedelta | Series[Timedelta]
251+
)
252+
253+
NumListLike: TypeAlias = ( # TODO: pandas-dev/pandas-stubs#1474 deprecated, do not use
173254
ExtensionArray
174255
| np_ndarray_bool
175256
| np_ndarray_anyint
@@ -281,7 +362,7 @@ class ElementOpsMixin(Generic[S2]):
281362
) -> ElementOpsMixin[complex]: ...
282363
@overload
283364
def _proto_truediv(
284-
self: ElementOpsMixin[Timedelta], other: timedelta | Timedelta | np.timedelta64
365+
self: ElementOpsMixin[Timedelta], other: timedelta | np.timedelta64 | Timedelta
285366
) -> ElementOpsMixin[float]: ...
286367
@overload
287368
def _proto_rtruediv(
@@ -297,8 +378,32 @@ class ElementOpsMixin(Generic[S2]):
297378
) -> ElementOpsMixin[complex]: ...
298379
@overload
299380
def _proto_rtruediv(
300-
self: ElementOpsMixin[Timedelta], other: timedelta | Timedelta | np.timedelta64
381+
self: ElementOpsMixin[Timedelta], other: timedelta | np.timedelta64 | Timedelta
382+
) -> ElementOpsMixin[float]: ...
383+
@overload
384+
def _proto_floordiv(
385+
self: ElementOpsMixin[int], other: int | np.integer
386+
) -> ElementOpsMixin[int]: ...
387+
@overload
388+
def _proto_floordiv(
389+
self: ElementOpsMixin[float], other: float | np.floating
301390
) -> ElementOpsMixin[float]: ...
391+
@overload
392+
def _proto_floordiv(
393+
self: ElementOpsMixin[Timedelta], other: timedelta | np.timedelta64 | Timedelta
394+
) -> ElementOpsMixin[int]: ...
395+
@overload
396+
def _proto_rfloordiv(
397+
self: ElementOpsMixin[int], other: int | np.integer
398+
) -> ElementOpsMixin[int]: ...
399+
@overload
400+
def _proto_rfloordiv(
401+
self: ElementOpsMixin[float], other: float | np.floating
402+
) -> ElementOpsMixin[float]: ...
403+
@overload
404+
def _proto_rfloordiv(
405+
self: ElementOpsMixin[Timedelta], other: timedelta | np.timedelta64 | Timedelta
406+
) -> ElementOpsMixin[int]: ...
302407

303408
@type_check_only
304409
class Supports_ProtoAdd(Protocol[_T_contra, S2]):
@@ -323,3 +428,11 @@ class Supports_ProtoTrueDiv(Protocol[_T_contra, S2]):
323428
@type_check_only
324429
class Supports_ProtoRTrueDiv(Protocol[_T_contra, S2]):
325430
def _proto_rtruediv(self, other: _T_contra, /) -> ElementOpsMixin[S2]: ...
431+
432+
@type_check_only
433+
class Supports_ProtoFloorDiv(Protocol[_T_contra, S2]):
434+
def _proto_floordiv(self, other: _T_contra, /) -> ElementOpsMixin[S2]: ...
435+
436+
@type_check_only
437+
class Supports_ProtoRFloorDiv(Protocol[_T_contra, S2]):
438+
def _proto_rfloordiv(self, other: _T_contra, /) -> ElementOpsMixin[S2]: ...

0 commit comments

Comments
 (0)