Skip to content

Commit 3212e19

Browse files
committed
Merge remote-tracking branch 'upstream/main' into clean-iterable
2 parents 96fbc5e + 085653b commit 3212e19

Some content is hidden

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

77 files changed

+491
-700
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,6 @@ dmypy.json
135135
.pyre/
136136
/poetry.lock
137137
.idea/**/*
138+
139+
# duplication of stub specific objects upon testing
140+
tests/_typing.pyi

pandas-stubs/_libs/missing.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class NAType:
117117
@overload
118118
def __eq__(self, other: Index, /) -> BooleanArray: ...
119119
@overload
120-
def __eq__( # pyright: ignore[reportIncompatibleMethodOverride]
120+
def __eq__( # pyright: ignore[reportIncompatibleMethodOverride] # ty: ignore[invalid-method-override]
121121
self, other: Scalar, /
122122
) -> NAType: ...
123123
@overload # type: ignore[override]
@@ -127,7 +127,7 @@ class NAType:
127127
@overload
128128
def __ne__(self, other: Index, /) -> BooleanArray: ...
129129
@overload
130-
def __ne__( # pyright: ignore[reportIncompatibleMethodOverride]
130+
def __ne__( # pyright: ignore[reportIncompatibleMethodOverride] # ty: ignore[invalid-method-override]
131131
self, other: Scalar, /
132132
) -> NAType: ...
133133
@overload

pandas-stubs/_libs/tslibs/timedeltas.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ class Timedelta(timedelta):
259259
self, other: np_ndarray[ShapeT, np.integer | np.floating]
260260
) -> np_ndarray[ShapeT, np.timedelta64]: ...
261261
@overload
262-
def __truediv__(
262+
def __truediv__( # ty: ignore[invalid-method-override]
263263
self, other: np_ndarray[ShapeT, np.timedelta64]
264264
) -> np_ndarray[ShapeT, np.floating]: ...
265265
@overload

pandas-stubs/_libs/tslibs/timestamps.pyi

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ from pandas._libs.tslibs import (
3232
Tick,
3333
Timedelta,
3434
)
35+
from pandas._libs.tslibs.nattype import NaTType
3536
from pandas._typing import (
3637
PeriodFrequency,
3738
ShapeT,
@@ -180,7 +181,9 @@ class Timestamp(datetime, SupportsIndex):
180181
self, other: np_ndarray[ShapeT, np.datetime64]
181182
) -> np_ndarray[ShapeT, np.bool]: ...
182183
@overload
183-
def __le__(self, other: Series[Timestamp]) -> Series[bool]: ...
184+
def __le__( # ty: ignore[invalid-method-override]
185+
self, other: Series[Timestamp]
186+
) -> Series[bool]: ...
184187
@overload # type: ignore[override]
185188
def __lt__(self, other: datetime | np.datetime64 | Self) -> bool: ...
186189
@overload
@@ -190,7 +193,9 @@ class Timestamp(datetime, SupportsIndex):
190193
self, other: np_ndarray[ShapeT, np.datetime64]
191194
) -> np_ndarray[ShapeT, np.bool]: ...
192195
@overload
193-
def __lt__(self, other: Series[Timestamp]) -> Series[bool]: ...
196+
def __lt__( # ty: ignore[invalid-method-override]
197+
self, other: Series[Timestamp]
198+
) -> Series[bool]: ...
194199
@overload # type: ignore[override]
195200
def __ge__(self, other: datetime | np.datetime64 | Self) -> bool: ...
196201
@overload
@@ -200,7 +205,9 @@ class Timestamp(datetime, SupportsIndex):
200205
self, other: np_ndarray[ShapeT, np.datetime64]
201206
) -> np_ndarray[ShapeT, np.bool]: ...
202207
@overload
203-
def __ge__(self, other: Series[Timestamp]) -> Series[bool]: ...
208+
def __ge__( # ty: ignore[invalid-method-override]
209+
self, other: Series[Timestamp]
210+
) -> Series[bool]: ...
204211
@overload # type: ignore[override]
205212
def __gt__(self, other: datetime | np.datetime64 | Self) -> bool: ...
206213
@overload
@@ -210,7 +217,9 @@ class Timestamp(datetime, SupportsIndex):
210217
self, other: np_ndarray[ShapeT, np.datetime64]
211218
) -> np_ndarray[ShapeT, np.bool]: ...
212219
@overload
213-
def __gt__(self, other: Series[Timestamp]) -> Series[bool]: ...
220+
def __gt__( # ty: ignore[invalid-method-override]
221+
self, other: Series[Timestamp]
222+
) -> Series[bool]: ...
214223
# error: Signature of "__add__" incompatible with supertype "date"/"datetime"
215224
@overload # type: ignore[override]
216225
def __add__(
@@ -228,15 +237,15 @@ class Timestamp(datetime, SupportsIndex):
228237
def __radd__(
229238
self, other: np_ndarray[ShapeT, np.timedelta64]
230239
) -> np_ndarray[ShapeT, np.datetime64]: ...
231-
# TODO: pandas-dev/pandas-stubs#1432 test dt64
240+
def __rsub__(self, other: datetime | np.datetime64) -> Timedelta: ...
232241
@overload # type: ignore[override]
233242
def __sub__(self, other: datetime | np.datetime64) -> Timedelta: ...
234243
@overload
235244
def __sub__(self, other: timedelta | np.timedelta64 | Tick) -> Self: ...
236245
@overload
237246
def __sub__(self, other: TimedeltaIndex) -> DatetimeIndex: ...
238247
@overload
239-
def __sub__(
248+
def __sub__( # ty: ignore[invalid-method-override]
240249
self, other: np_ndarray[ShapeT, np.timedelta64]
241250
) -> np_ndarray[ShapeT, np.datetime64]: ...
242251
@overload
@@ -284,7 +293,15 @@ class Timestamp(datetime, SupportsIndex):
284293
@property
285294
def asm8(self) -> np.datetime64: ...
286295
def tz_convert(self, tz: TimeZones) -> Self: ...
287-
# TODO: pandas-dev/pandas-stubs#1432 could return NaT?
296+
@overload
297+
def tz_localize( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
298+
self,
299+
tz: TimeZones,
300+
ambiguous: _Ambiguous = "raise",
301+
*,
302+
nonexistent: Literal["NaT"],
303+
) -> Self | NaTType: ...
304+
@overload
288305
def tz_localize(
289306
self,
290307
tz: TimeZones,

pandas-stubs/_typing.pyi

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ from os import PathLike
1414
from re import Pattern
1515
import sys
1616
from typing import (
17+
TYPE_CHECKING,
1718
Any,
1819
Generic,
1920
Literal,
@@ -25,7 +26,6 @@ from typing import (
2526
overload,
2627
)
2728

28-
from _typeshed import _T_contra
2929
import numpy as np
3030
from numpy import typing as npt
3131
import pandas as pd
@@ -87,13 +87,15 @@ HashableT5 = TypeVar("HashableT5", bound=Hashable)
8787

8888
ArrayLike: TypeAlias = ExtensionArray | npt.NDArray[Any]
8989
AnyArrayLike: TypeAlias = ArrayLike | Index | Series
90-
AnyArrayLikeInt: TypeAlias = (
91-
IntegerArray | Index[int] | Series[int] | npt.NDArray[np.integer]
92-
)
90+
if TYPE_CHECKING: # noqa: PYI002
91+
AnyArrayLikeInt: TypeAlias = (
92+
IntegerArray | Index[int] | Series[int] | npt.NDArray[np.integer]
93+
)
9394

9495
# list-like
9596

9697
_T_co = TypeVar("_T_co", covariant=True)
98+
_T_contra = TypeVar("_T_contra", contravariant=True)
9799

98100
class SequenceNotStr(Protocol[_T_co]):
99101
@overload
@@ -966,8 +968,9 @@ class SupportsDType(Protocol[GenericT_co]):
966968
# Similar to npt.DTypeLike but leaves out np.dtype and None for use in overloads
967969
DTypeLike: TypeAlias = type[Any] | tuple[Any, Any] | list[Any] | str
968970

969-
IndexType: TypeAlias = slice | np_ndarray_anyint | Index | list[int] | Series[int]
970-
MaskType: TypeAlias = Series[bool] | np_ndarray_bool | list[bool]
971+
if TYPE_CHECKING: # noqa: PYI002
972+
IndexType: TypeAlias = slice | np_ndarray_anyint | Index | list[int] | Series[int]
973+
MaskType: TypeAlias = Series[bool] | np_ndarray_bool | list[bool]
971974

972975
# Scratch types for generics
973976

@@ -1039,48 +1042,49 @@ Function: TypeAlias = np.ufunc | Callable[..., Any]
10391042
# shared HashableT and HashableT#. This one can be used if the identical
10401043
# type is need in a function that uses GroupByObjectNonScalar
10411044
_HashableTa = TypeVar("_HashableTa", bound=Hashable)
1042-
ByT = TypeVar(
1043-
"ByT",
1044-
bound=str
1045-
| bytes
1046-
| datetime.date
1047-
| datetime.datetime
1048-
| datetime.timedelta
1049-
| np.datetime64
1050-
| np.timedelta64
1051-
| bool
1052-
| int
1053-
| float
1054-
| complex
1055-
| Scalar
1056-
| Period
1057-
| Interval[int | float | Timestamp | Timedelta]
1058-
| tuple,
1059-
)
1060-
# Use a distinct SeriesByT when using groupby with Series of known dtype.
1061-
# Essentially, an intersection between Series S1 TypeVar, and ByT TypeVar
1062-
SeriesByT = TypeVar(
1063-
"SeriesByT",
1064-
bound=str
1065-
| bytes
1066-
| datetime.date
1067-
| bool
1068-
| int
1069-
| float
1070-
| complex
1071-
| datetime.datetime
1072-
| datetime.timedelta
1073-
| Period
1074-
| Interval[int | float | Timestamp | Timedelta],
1075-
)
1045+
if TYPE_CHECKING: # noqa: PYI002
1046+
ByT = TypeVar(
1047+
"ByT",
1048+
bound=str
1049+
| bytes
1050+
| datetime.date
1051+
| datetime.datetime
1052+
| datetime.timedelta
1053+
| np.datetime64
1054+
| np.timedelta64
1055+
| bool
1056+
| int
1057+
| float
1058+
| complex
1059+
| Scalar
1060+
| Period
1061+
| Interval[int | float | Timestamp | Timedelta]
1062+
| tuple,
1063+
)
1064+
# Use a distinct SeriesByT when using groupby with Series of known dtype.
1065+
# Essentially, an intersection between Series S1 TypeVar, and ByT TypeVar
1066+
SeriesByT = TypeVar(
1067+
"SeriesByT",
1068+
bound=str
1069+
| bytes
1070+
| datetime.date
1071+
| bool
1072+
| int
1073+
| float
1074+
| complex
1075+
| datetime.datetime
1076+
| datetime.timedelta
1077+
| Period
1078+
| Interval[int | float | Timestamp | Timedelta],
1079+
)
10761080
GroupByObjectNonScalar: TypeAlias = (
10771081
tuple
10781082
| list[_HashableTa]
10791083
| Function
10801084
| list[Function]
10811085
| list[Series]
1082-
| np.ndarray
1083-
| list[np.ndarray]
1086+
| np_ndarray
1087+
| list[np_ndarray]
10841088
| Mapping[Label, Any]
10851089
| list[Mapping[Label, Any]]
10861090
| list[Index]

pandas-stubs/core/arrays/categorical.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ class Categorical(ExtensionArray):
111111
def take(
112112
self, indexer: TakeIndexer, *, allow_fill: bool = ..., fill_value=...
113113
) -> Categorical: ...
114-
def __contains__(self, key) -> bool: ...
114+
def __contains__(self, item) -> bool: ...
115115
@overload
116116
def __getitem__(self, key: ScalarIndexer) -> Any: ...
117117
@overload
118-
def __getitem__(
118+
def __getitem__( # ty: ignore[invalid-method-override]
119119
self,
120120
key: SequenceIndexer | PositionalIndexerTuple,
121121
) -> Self: ...

pandas-stubs/core/arrays/datetimelike.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ class DatetimeLikeArrayMixin(ExtensionOpsMixin, ExtensionArray):
7373
@overload
7474
def __getitem__(self, key: ScalarIndexer) -> DTScalarOrNaT: ...
7575
@overload
76-
def __getitem__(
76+
def __getitem__( # ty: ignore[invalid-method-override]
7777
self,
78-
key: SequenceIndexer | PositionalIndexerTuple,
78+
item: SequenceIndexer | PositionalIndexerTuple,
7979
) -> Self: ...
8080
def __setitem__( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
8181
self, key: int | Sequence[int] | Sequence[bool] | slice, value

pandas-stubs/core/arrays/interval.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ class IntervalArray(IntervalMixin, ExtensionArray):
6161
self, dtype: NpDtype | None = None, copy: bool | None = None
6262
) -> np_1darray: ...
6363
@overload
64-
def __getitem__(self, key: ScalarIndexer) -> IntervalOrNA: ...
64+
def __getitem__(self, item: ScalarIndexer) -> IntervalOrNA: ...
6565
@overload
66-
def __getitem__(self, key: SequenceIndexer) -> Self: ...
66+
def __getitem__(self, item: SequenceIndexer) -> Self: ...
6767
def __setitem__(self, key, value) -> None: ...
6868
def __eq__(self, other): ...
6969
def __ne__(self, other): ...

pandas-stubs/core/arrays/sparse/array.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ class SparseArray(ExtensionArray, ExtensionOpsMixin):
6363
@overload
6464
def __getitem__(self, key: ScalarIndexer) -> Any: ...
6565
@overload
66-
def __getitem__(
66+
def __getitem__( # ty: ignore[invalid-method-override]
6767
self,
68-
key: SequenceIndexer | tuple[int | ellipsis, ...],
68+
item: SequenceIndexer | tuple[int | ellipsis, ...],
6969
) -> Self: ...
7070
def copy(self): ...
7171
def map(self, mapper): ...

pandas-stubs/core/base.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ from typing import (
1010
Literal,
1111
Protocol,
1212
TypeAlias,
13+
TypeVar,
1314
final,
1415
overload,
1516
type_check_only,
@@ -53,6 +54,8 @@ from pandas._typing import (
5354
)
5455
from pandas.util._decorators import cache_readonly
5556

57+
T_INTERVAL_NP = TypeVar("T_INTERVAL_NP", bound=np.bytes_ | np.str_)
58+
5659
class NoNewAttributesMixin:
5760
def __setattr__(self, key: str, value: Any) -> None: ...
5861

0 commit comments

Comments
 (0)