Skip to content

Commit 4764c07

Browse files
committed
Merge remote-tracking branch 'upstream/main' into series-map
2 parents b672627 + cbdaaf1 commit 4764c07

File tree

108 files changed

+1463
-1189
lines changed

Some content is hidden

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

108 files changed

+1463
-1189
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/__init__.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ from pandas.core.api import (
6363
to_numeric as to_numeric,
6464
to_timedelta as to_timedelta,
6565
unique as unique,
66-
value_counts as value_counts,
6766
)
6867
from pandas.core.arrays.sparse import SparseDtype as SparseDtype
6968
from pandas.core.computation.api import eval as eval

pandas-stubs/_libs/json.pyi

Lines changed: 0 additions & 6 deletions
This file was deleted.

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/properties.pyi

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,4 @@
1-
from collections.abc import Callable
2-
3-
class CachedProperty:
4-
def __init__(self, func: Callable) -> None: ...
5-
def __get__(self, obj, typ): ...
6-
def __set__(self, obj, value) -> None: ...
7-
81
# note: this is a lie to make type checkers happy (they special
92
# case property). cache_readonly uses attribute names similar to
103
# property (fget) but it does not provide fset and fdel.
114
cache_readonly = property
12-
13-
class AxisProperty:
14-
def __init__(self, axis: int = ..., doc: str = ...) -> None: ...
15-
def __get__(self, obj, typ): ...
16-
def __set__(self, obj, value) -> None: ...

pandas-stubs/_libs/tslibs/offsets.pyi

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class BaseOffset:
4545
self, other: np_ndarray[ShapeT, np.object_]
4646
) -> np_ndarray[ShapeT, np.object_]: ...
4747
@overload
48-
def __add__(self, other: _DatetimeT) -> _DatetimeT: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
48+
def __add__(self, other: _DatetimeT) -> _DatetimeT: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
4949
@overload
5050
def __add__(self, other: date) -> Timestamp: ...
5151
@overload
@@ -57,7 +57,7 @@ class BaseOffset:
5757
self, other: np_ndarray[ShapeT, np.object_]
5858
) -> np_ndarray[ShapeT, np.object_]: ...
5959
@overload
60-
def __radd__(self, other: _DatetimeT) -> _DatetimeT: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
60+
def __radd__(self, other: _DatetimeT) -> _DatetimeT: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
6161
@overload
6262
def __radd__(self, other: date) -> Timestamp: ...
6363
@overload
@@ -68,7 +68,7 @@ class BaseOffset:
6868
@overload
6969
def __rsub__(self, other: npt.NDArray[np.object_]) -> npt.NDArray[np.object_]: ...
7070
@overload
71-
def __rsub__(self, other: _DatetimeT) -> _DatetimeT: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
71+
def __rsub__(self, other: _DatetimeT) -> _DatetimeT: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
7272
@overload
7373
def __rsub__(self, other: date) -> Timestamp: ...
7474
@overload
@@ -124,7 +124,6 @@ class BusinessDay(BaseOffset):
124124
def __init__(
125125
self, n: int = ..., normalize: bool = ..., offset: timedelta = ...
126126
) -> None: ...
127-
def __reduce__(self): ...
128127

129128
class BusinessHour(SingleConstructorOffset):
130129
def __init__(

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: 25 additions & 8 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,
@@ -99,7 +100,7 @@ class Timestamp(datetime, SupportsIndex):
99100
def fold(self) -> int: ...
100101
if sys.version_info >= (3, 12):
101102
@classmethod
102-
def fromtimestamp( # pyright: ignore[reportIncompatibleMethodOverride]
103+
def fromtimestamp( # pyright: ignore[reportIncompatibleMethodOverride] # ty: ignore[invalid-method-override] # pyrefly: ignore[bad-param-name-override]
103104
cls, t: float, tz: _tzinfo | str | None = ...
104105
) -> Self: ...
105106
else:
@@ -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: 68 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,17 @@ 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,
2021
Protocol,
2122
SupportsIndex,
2223
TypeAlias,
2324
TypedDict,
24-
Union,
2525
overload,
2626
)
2727

28-
from _typeshed import _T_contra
2928
import numpy as np
3029
from numpy import typing as npt
3130
import pandas as pd
@@ -87,13 +86,15 @@ HashableT5 = TypeVar("HashableT5", bound=Hashable)
8786

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

9494
# list-like
9595

9696
_T_co = TypeVar("_T_co", covariant=True)
97+
_T_contra = TypeVar("_T_contra", contravariant=True)
9798

9899
class SequenceNotStr(Protocol[_T_co]):
99100
@overload
@@ -594,18 +595,25 @@ IndexKeyFunc: TypeAlias = Callable[[Index], Index | AnyArrayLike] | None
594595

595596
# types of `func` kwarg for DataFrame.aggregate and Series.aggregate
596597
# More specific than what is in pandas
597-
# following Union is here to make it ty compliant https://github.com/astral-sh/ty/issues/591
598-
AggFuncTypeBase: TypeAlias = Union[Callable, str, np.ufunc] # noqa: UP007
599-
AggFuncTypeDictSeries: TypeAlias = Mapping[HashableT, AggFuncTypeBase]
598+
AggFuncTypeBase: TypeAlias = Callable[P, Any] | str | np.ufunc
599+
AggFuncTypeDictSeries: TypeAlias = Mapping[HashableT, AggFuncTypeBase[P]]
600600
AggFuncTypeDictFrame: TypeAlias = Mapping[
601-
HashableT, AggFuncTypeBase | list[AggFuncTypeBase]
601+
HashableT, AggFuncTypeBase[P] | Sequence[AggFuncTypeBase[P]]
602602
]
603-
AggFuncTypeSeriesToFrame: TypeAlias = list[AggFuncTypeBase] | AggFuncTypeDictSeries
603+
AggFuncTypeSeriesToFrame: TypeAlias = (
604+
Sequence[AggFuncTypeBase[P]] | AggFuncTypeDictSeries[HashableT, P]
605+
)
604606
AggFuncTypeFrame: TypeAlias = (
605-
AggFuncTypeBase | list[AggFuncTypeBase] | AggFuncTypeDictFrame
607+
AggFuncTypeBase[P]
608+
| Sequence[AggFuncTypeBase[P]]
609+
| AggFuncTypeDictFrame[HashableT, P]
610+
)
611+
AggFuncTypeDict: TypeAlias = (
612+
AggFuncTypeDictSeries[HashableT, P] | AggFuncTypeDictFrame[HashableT, P]
613+
)
614+
AggFuncType: TypeAlias = (
615+
AggFuncTypeBase[P] | Sequence[AggFuncTypeBase[P]] | AggFuncTypeDict[HashableT, P]
606616
)
607-
AggFuncTypeDict: TypeAlias = AggFuncTypeDictSeries | AggFuncTypeDictFrame
608-
AggFuncType: TypeAlias = AggFuncTypeBase | list[AggFuncTypeBase] | AggFuncTypeDict
609617

610618
# Not used in stubs
611619
# AggObjType = Union[
@@ -692,7 +700,9 @@ CompressionOptions: TypeAlias = (
692700

693701
# types in DataFrameFormatter
694702
FormattersType: TypeAlias = (
695-
list[Callable] | tuple[Callable, ...] | Mapping[str | int, Callable]
703+
list[Callable[..., Any]]
704+
| tuple[Callable[..., Any], ...]
705+
| Mapping[str | int, Callable[..., Any]]
696706
)
697707
# ColspaceType = Mapping[Hashable, Union[str, int]] not used in stubs
698708
FloatFormatType: TypeAlias = str | Callable[[float], str] | EngFormatter
@@ -825,7 +835,7 @@ TimeNonexistent: TypeAlias = (
825835
DropKeep: TypeAlias = Literal["first", "last", False]
826836
CorrelationMethod: TypeAlias = (
827837
Literal["pearson", "kendall", "spearman"]
828-
| Callable[[np.typing.NDArray[Any], np.typing.NDArray[Any]], float]
838+
| Callable[[npt.NDArray[Any], npt.NDArray[Any]], float]
829839
)
830840
AlignJoin: TypeAlias = Literal["outer", "inner", "left", "right"]
831841
DtypeBackend: TypeAlias = Literal["pyarrow", "numpy_nullable"]
@@ -948,6 +958,8 @@ np_1darray_dt: TypeAlias = np_1darray[np.datetime64]
948958
np_1darray_td: TypeAlias = np_1darray[np.timedelta64]
949959
np_2darray: TypeAlias = np.ndarray[tuple[int, int], np.dtype[GenericT]]
950960

961+
NDArrayT = TypeVar("NDArrayT", bound=np.ndarray)
962+
951963
DtypeNp = TypeVar("DtypeNp", bound=np.dtype[np.generic])
952964
KeysArgType: TypeAlias = Any
953965
ListLikeT = TypeVar("ListLikeT", bound=ListLike)
@@ -966,8 +978,9 @@ class SupportsDType(Protocol[GenericT_co]):
966978
# Similar to npt.DTypeLike but leaves out np.dtype and None for use in overloads
967979
DTypeLike: TypeAlias = type[Any] | tuple[Any, Any] | list[Any] | str
968980

969-
IndexType: TypeAlias = slice | np_ndarray_anyint | Index | list[int] | Series[int]
970-
MaskType: TypeAlias = Series[bool] | np_ndarray_bool | list[bool]
981+
if TYPE_CHECKING: # noqa: PYI002
982+
IndexType: TypeAlias = slice | np_ndarray_anyint | Index | list[int] | Series[int]
983+
MaskType: TypeAlias = Series[bool] | np_ndarray_bool | list[bool]
971984

972985
# Scratch types for generics
973986

@@ -1039,48 +1052,49 @@ Function: TypeAlias = np.ufunc | Callable[..., Any]
10391052
# shared HashableT and HashableT#. This one can be used if the identical
10401053
# type is need in a function that uses GroupByObjectNonScalar
10411054
_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-
)
1055+
if TYPE_CHECKING: # noqa: PYI002
1056+
ByT = TypeVar(
1057+
"ByT",
1058+
bound=str
1059+
| bytes
1060+
| datetime.date
1061+
| datetime.datetime
1062+
| datetime.timedelta
1063+
| np.datetime64
1064+
| np.timedelta64
1065+
| bool
1066+
| int
1067+
| float
1068+
| complex
1069+
| Scalar
1070+
| Period
1071+
| Interval[int | float | Timestamp | Timedelta]
1072+
| tuple,
1073+
)
1074+
# Use a distinct SeriesByT when using groupby with Series of known dtype.
1075+
# Essentially, an intersection between Series S1 TypeVar, and ByT TypeVar
1076+
SeriesByT = TypeVar(
1077+
"SeriesByT",
1078+
bound=str
1079+
| bytes
1080+
| datetime.date
1081+
| bool
1082+
| int
1083+
| float
1084+
| complex
1085+
| datetime.datetime
1086+
| datetime.timedelta
1087+
| Period
1088+
| Interval[int | float | Timestamp | Timedelta],
1089+
)
10761090
GroupByObjectNonScalar: TypeAlias = (
1077-
tuple
1091+
tuple[_HashableTa, ...]
10781092
| list[_HashableTa]
10791093
| Function
10801094
| list[Function]
10811095
| list[Series]
1082-
| np.ndarray
1083-
| list[np.ndarray]
1096+
| np_ndarray
1097+
| list[np_ndarray]
10841098
| Mapping[Label, Any]
10851099
| list[Mapping[Label, Any]]
10861100
| list[Index]

0 commit comments

Comments
 (0)