Skip to content

Commit e124d56

Browse files
committed
Merge remote-tracking branch 'upstream/main' into typ-period
2 parents df651aa + 966aebf commit e124d56

24 files changed

+2764
-294
lines changed

pandas-stubs/_typing.pyi

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ from re import Pattern
1515
import sys
1616
from typing import (
1717
Any,
18+
Generic,
1819
Literal,
1920
Protocol,
2021
SupportsIndex,
@@ -37,6 +38,7 @@ from typing_extensions import (
3738
ParamSpec,
3839
TypeAlias,
3940
TypeVar,
41+
override,
4042
)
4143

4244
from pandas._libs.interval import Interval
@@ -818,6 +820,8 @@ np_ndarray_float: TypeAlias = npt.NDArray[np.floating]
818820
np_ndarray_complex: TypeAlias = npt.NDArray[np.complexfloating]
819821
np_ndarray_bool: TypeAlias = npt.NDArray[np.bool_]
820822
np_ndarray_str: TypeAlias = npt.NDArray[np.str_]
823+
np_ndarray_dt: TypeAlias = npt.NDArray[np.datetime64]
824+
np_ndarray_td: TypeAlias = npt.NDArray[np.timedelta64]
821825

822826
# Define shape and generic type variables with defaults similar to numpy
823827
GenericT = TypeVar("GenericT", bound=np.generic, default=Any)
@@ -1055,4 +1059,14 @@ DictConvertible: TypeAlias = FulldatetimeDict | DataFrame
10551059
# where it is the only acceptable type.
10561060
Incomplete: TypeAlias = Any
10571061

1062+
# differentiating between bool and int/float/complex
1063+
# https://github.com/pandas-dev/pandas-stubs/pull/1312#pullrequestreview-3126128971
1064+
class Just(Protocol, Generic[T]):
1065+
@property # type: ignore[override]
1066+
@override
1067+
def __class__(self, /) -> type[T]: ...
1068+
@__class__.setter
1069+
@override
1070+
def __class__(self, t: type[T], /) -> None: ...
1071+
10581072
__all__ = ["npt", "type_t"]

pandas-stubs/core/groupby/generic.pyi

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,13 @@ class DataFrameGroupBy(GroupBy[DataFrame], Generic[ByT, _TT]):
264264
engine_kwargs: WindowingEngineKwargs = ...,
265265
**kwargs,
266266
) -> DataFrame: ...
267+
@overload
268+
def aggregate(
269+
self,
270+
func: AggFuncTypeFrame | None = None,
271+
/,
272+
**kwargs,
273+
) -> DataFrame: ...
267274
agg = aggregate
268275
@overload
269276
def transform(

pandas-stubs/core/groupby/groupby.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ from pandas._typing import (
7474
from pandas.plotting import PlotAccessor
7575

7676
_ResamplerGroupBy: TypeAlias = (
77-
DatetimeIndexResamplerGroupby[NDFrameT]
78-
| PeriodIndexResamplerGroupby[NDFrameT]
79-
| TimedeltaIndexResamplerGroupby[NDFrameT]
77+
DatetimeIndexResamplerGroupby[NDFrameT] # ty: ignore[invalid-argument-type]
78+
| PeriodIndexResamplerGroupby[NDFrameT] # ty: ignore[invalid-argument-type]
79+
| TimedeltaIndexResamplerGroupby[NDFrameT] # ty: ignore[invalid-argument-type]
8080
)
8181

8282
class GroupBy(BaseGroupBy[NDFrameT]):

pandas-stubs/core/indexes/datetimes.pyi

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,46 @@ class DatetimeIndex(
102102
self, periods: int = 1, freq: DateOffset | Timedelta | str | None = None
103103
) -> Self: ...
104104

105+
@overload
106+
def date_range(
107+
start: str | DateAndDatetimeLike,
108+
end: str | DateAndDatetimeLike,
109+
freq: str | timedelta | Timedelta | BaseOffset | None = None,
110+
tz: TimeZones = None,
111+
normalize: bool = False,
112+
name: Hashable | None = None,
113+
inclusive: IntervalClosedType = "both",
114+
unit: TimeUnit | None = None,
115+
) -> DatetimeIndex: ...
116+
@overload
105117
def date_range(
106-
start: str | DateAndDatetimeLike | None = None,
107-
end: str | DateAndDatetimeLike | None = None,
108-
periods: int | None = None,
109-
freq: str | timedelta | Timedelta | BaseOffset = "D",
118+
start: str | DateAndDatetimeLike,
119+
end: str | DateAndDatetimeLike,
120+
periods: int,
121+
tz: TimeZones = None,
122+
normalize: bool = False,
123+
name: Hashable | None = None,
124+
inclusive: IntervalClosedType = "both",
125+
unit: TimeUnit | None = None,
126+
) -> DatetimeIndex: ...
127+
@overload
128+
def date_range(
129+
start: str | DateAndDatetimeLike,
130+
*,
131+
periods: int,
132+
freq: str | timedelta | Timedelta | BaseOffset | None = None,
133+
tz: TimeZones = None,
134+
normalize: bool = False,
135+
name: Hashable | None = None,
136+
inclusive: IntervalClosedType = "both",
137+
unit: TimeUnit | None = None,
138+
) -> DatetimeIndex: ...
139+
@overload
140+
def date_range(
141+
*,
142+
end: str | DateAndDatetimeLike,
143+
periods: int,
144+
freq: str | timedelta | Timedelta | BaseOffset | None = None,
110145
tz: TimeZones = None,
111146
normalize: bool = False,
112147
name: Hashable | None = None,

pandas-stubs/core/indexes/timedeltas.pyi

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,43 @@ class TimedeltaIndex(
7979
def to_series(self, index=..., name: Hashable = ...) -> TimedeltaSeries: ...
8080
def shift(self, periods: int = 1, freq=...) -> Self: ...
8181

82+
@overload
8283
def timedelta_range(
83-
start: TimedeltaConvertibleTypes | None = None,
84-
end: TimedeltaConvertibleTypes | None = None,
85-
periods: int | None = None,
84+
start: TimedeltaConvertibleTypes,
85+
end: TimedeltaConvertibleTypes,
86+
*,
87+
freq: str | DateOffset | Timedelta | dt.timedelta | None = None,
88+
name: Hashable | None = None,
89+
closed: Literal["left", "right"] | None = None,
90+
unit: None | str = ...,
91+
) -> TimedeltaIndex: ...
92+
@overload
93+
def timedelta_range(
94+
*,
95+
end: TimedeltaConvertibleTypes,
96+
periods: int,
97+
freq: str | DateOffset | Timedelta | dt.timedelta | None = None,
98+
name: Hashable | None = None,
99+
closed: Literal["left", "right"] | None = None,
100+
unit: None | str = ...,
101+
) -> TimedeltaIndex: ...
102+
@overload
103+
def timedelta_range(
104+
start: TimedeltaConvertibleTypes,
105+
*,
106+
periods: int,
86107
freq: str | DateOffset | Timedelta | dt.timedelta | None = None,
87108
name: Hashable | None = None,
88109
closed: Literal["left", "right"] | None = None,
110+
unit: None | str = ...,
111+
) -> TimedeltaIndex: ...
112+
@overload
113+
def timedelta_range(
114+
start: TimedeltaConvertibleTypes,
115+
end: TimedeltaConvertibleTypes,
116+
periods: int,
89117
*,
118+
name: Hashable | None = None,
119+
closed: Literal["left", "right"] | None = None,
90120
unit: None | str = ...,
91121
) -> TimedeltaIndex: ...

0 commit comments

Comments
 (0)