Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas-stubs/_libs/tslibs/timestamps.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class Timestamp(datetime, SupportsIndex):
def fold(self) -> int: ...
if sys.version_info >= (3, 12):
@classmethod
def fromtimestamp( # pyright: ignore[reportIncompatibleMethodOverride]
def fromtimestamp( # pyright: ignore[reportIncompatibleMethodOverride] # ty: ignore[invalid-method-override]
cls, t: float, tz: _tzinfo | str | None = ...
) -> Self: ...
else:
Expand Down
28 changes: 18 additions & 10 deletions pandas-stubs/_typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ from typing import (
SupportsIndex,
TypeAlias,
TypedDict,
Union,
overload,
)

Expand Down Expand Up @@ -596,18 +595,25 @@ IndexKeyFunc: TypeAlias = Callable[[Index], Index | AnyArrayLike] | None

# types of `func` kwarg for DataFrame.aggregate and Series.aggregate
# More specific than what is in pandas
# following Union is here to make it ty compliant https://github.com/astral-sh/ty/issues/591
AggFuncTypeBase: TypeAlias = Union[Callable, str, np.ufunc] # noqa: UP007
AggFuncTypeDictSeries: TypeAlias = Mapping[HashableT, AggFuncTypeBase]
AggFuncTypeBase: TypeAlias = Callable[P, Any] | str | np.ufunc
AggFuncTypeDictSeries: TypeAlias = Mapping[HashableT, AggFuncTypeBase[P]]
AggFuncTypeDictFrame: TypeAlias = Mapping[
HashableT, AggFuncTypeBase | list[AggFuncTypeBase]
HashableT, AggFuncTypeBase[P] | Sequence[AggFuncTypeBase[P]]
]
AggFuncTypeSeriesToFrame: TypeAlias = list[AggFuncTypeBase] | AggFuncTypeDictSeries
AggFuncTypeSeriesToFrame: TypeAlias = (
Sequence[AggFuncTypeBase[P]] | AggFuncTypeDictSeries[HashableT, P]
)
AggFuncTypeFrame: TypeAlias = (
AggFuncTypeBase | list[AggFuncTypeBase] | AggFuncTypeDictFrame
AggFuncTypeBase[P]
| Sequence[AggFuncTypeBase[P]]
| AggFuncTypeDictFrame[HashableT, P]
)
AggFuncTypeDict: TypeAlias = (
AggFuncTypeDictSeries[HashableT, P] | AggFuncTypeDictFrame[HashableT, P]
)
AggFuncType: TypeAlias = (
AggFuncTypeBase[P] | Sequence[AggFuncTypeBase[P]] | AggFuncTypeDict
)
AggFuncTypeDict: TypeAlias = AggFuncTypeDictSeries | AggFuncTypeDictFrame
AggFuncType: TypeAlias = AggFuncTypeBase | list[AggFuncTypeBase] | AggFuncTypeDict

# Not used in stubs
# AggObjType = Union[
Expand Down Expand Up @@ -694,7 +700,9 @@ CompressionOptions: TypeAlias = (

# types in DataFrameFormatter
FormattersType: TypeAlias = (
list[Callable] | tuple[Callable, ...] | Mapping[str | int, Callable]
list[Callable[..., Any]]
| tuple[Callable[..., Any], ...]
| Mapping[str | int, Callable[..., Any]]
)
# ColspaceType = Mapping[Hashable, Union[str, int]] not used in stubs
FloatFormatType: TypeAlias = str | Callable[[float], str] | EngFormatter
Expand Down
39 changes: 25 additions & 14 deletions pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ class _LocIndexerFrame(_LocIndexer, Generic[_T]):
| list[HashableT]
| slice
| _IndexSliceTuple
| Callable,
MaskType | Iterable[HashableT] | IndexType | Callable,
| Callable[..., Any],
MaskType | Iterable[HashableT] | IndexType | Callable[..., Any],
]
),
) -> _T: ...
Expand Down Expand Up @@ -1268,7 +1268,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
def combine(
self,
other: DataFrame,
func: Callable,
func: Callable[..., Any],
fill_value: Scalar | None = None,
overwrite: _bool = True,
) -> Self: ...
Expand All @@ -1278,7 +1278,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
other: DataFrame | Series,
join: UpdateJoin = "left",
overwrite: _bool = True,
filter_func: Callable | None = ...,
filter_func: Callable[..., Any] | None = ...,
errors: IgnoreRaise = "ignore",
) -> None: ...
@overload
Expand Down Expand Up @@ -1516,21 +1516,21 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
@overload
def aggregate( # pyright: ignore[reportOverlappingOverload]
self,
func: AggFuncTypeBase | AggFuncTypeDictSeries,
func: AggFuncTypeBase[...] | AggFuncTypeDictSeries[Any, ...],
axis: Axis = 0,
**kwargs: Any,
) -> Series: ...
@overload
def aggregate(
self,
func: list[AggFuncTypeBase] | AggFuncTypeDictFrame | None = ...,
func: list[AggFuncTypeBase[...]] | AggFuncTypeDictFrame[Any, ...] | None = ...,
axis: Axis = 0,
**kwargs: Any,
) -> Self: ...
agg = aggregate
def transform(
self,
func: AggFuncTypeFrame,
func: AggFuncTypeFrame[..., Any],
axis: Axis = 0,
*args: Any,
**kwargs: Any,
Expand Down Expand Up @@ -1684,7 +1684,10 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):

# Add spacing between apply() overloads and remaining annotations
def map(
self, func: Callable, na_action: Literal["ignore"] | None = None, **kwargs: Any
self,
func: Callable[..., Any],
na_action: Literal["ignore"] | None = None,
**kwargs: Any,
) -> Self: ...
def join(
self,
Expand Down Expand Up @@ -2332,7 +2335,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
| Callable[[DataFrame], DataFrame]
| Callable[[Any], _bool]
),
other: Scalar | Series | DataFrame | Callable | NAType | None = ...,
other: Scalar | Series | DataFrame | Callable[..., Any] | NAType | None = ...,
*,
inplace: Literal[True],
axis: Axis | None = ...,
Expand All @@ -2349,7 +2352,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
| Callable[[DataFrame], DataFrame]
| Callable[[Any], _bool]
),
other: Scalar | Series | DataFrame | Callable | NAType | None = ...,
other: Scalar | Series | DataFrame | Callable[..., Any] | NAType | None = ...,
*,
inplace: Literal[False] = False,
axis: Axis | None = ...,
Expand Down Expand Up @@ -2510,8 +2513,12 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
def rename_axis(
self,
*,
index: _str | Sequence[_str] | dict[_str | int, _str] | Callable | None = ...,
columns: _str | Sequence[_str] | dict[_str | int, _str] | Callable | None = ...,
index: (
_str | Sequence[_str] | dict[_str | int, _str] | Callable[..., Any] | None
) = ...,
columns: (
_str | Sequence[_str] | dict[_str | int, _str] | Callable[..., Any] | None
) = ...,
copy: _bool = ...,
inplace: Literal[True],
) -> None: ...
Expand All @@ -2520,8 +2527,12 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
def rename_axis(
self,
*,
index: _str | Sequence[_str] | dict[_str | int, _str] | Callable | None = ...,
columns: _str | Sequence[_str] | dict[_str | int, _str] | Callable | None = ...,
index: (
_str | Sequence[_str] | dict[_str | int, _str] | Callable[..., Any] | None
) = ...,
columns: (
_str | Sequence[_str] | dict[_str | int, _str] | Callable[..., Any] | None
) = ...,
copy: _bool = ...,
inplace: Literal[False] = False,
) -> Self: ...
Expand Down
32 changes: 20 additions & 12 deletions pandas-stubs/core/groupby/generic.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class SeriesGroupBy(GroupBy[Series[S2]], Generic[S2, ByT]):
@overload
def aggregate(
self,
func: list[AggFuncTypeBase],
func: list[AggFuncTypeBase[...]],
/,
*args: Any,
engine: WindowingEngine = ...,
Expand All @@ -88,7 +88,7 @@ class SeriesGroupBy(GroupBy[Series[S2]], Generic[S2, ByT]):
@overload
def aggregate(
self,
func: AggFuncTypeBase | None = ...,
func: AggFuncTypeBase[...] | None = ...,
/,
*args: Any,
engine: WindowingEngine = ...,
Expand All @@ -109,16 +109,20 @@ class SeriesGroupBy(GroupBy[Series[S2]], Generic[S2, ByT]):
@overload
def transform(
self,
func: Callable,
*args: Any,
**kwargs: Any,
func: Callable[Concatenate[Series, P], Any],
*args: P.args,
**kwargs: P.kwargs,
) -> Series: ...
@overload
def transform(
self, func: TransformReductionListType, *args: Any, **kwargs: Any
) -> Series: ...
def filter(
self, func: Callable | str, dropna: bool = ..., *args: Any, **kwargs: Any
self,
func: Callable[Concatenate[Series, P], Any] | str,
dropna: bool = ...,
*args: P.args,
**kwargs: P.kwargs,
) -> Series: ...
def nunique(self, dropna: bool = ...) -> Series[int]: ...
# describe delegates to super() method but here it has keyword-only parameters
Expand Down Expand Up @@ -257,7 +261,7 @@ class DataFrameGroupBy(GroupBy[DataFrame], Generic[ByT, _TT]):
@overload
def aggregate(
self,
func: AggFuncTypeFrame | None = ...,
func: AggFuncTypeFrame[..., Any] | None = ...,
*args: Any,
engine: WindowingEngine = ...,
engine_kwargs: WindowingEngineKwargs = ...,
Expand All @@ -266,7 +270,7 @@ class DataFrameGroupBy(GroupBy[DataFrame], Generic[ByT, _TT]):
@overload
def aggregate(
self,
func: AggFuncTypeFrame | None = None,
func: AggFuncTypeFrame[..., Any] | None = None,
/,
**kwargs: Any,
) -> DataFrame: ...
Expand All @@ -283,16 +287,20 @@ class DataFrameGroupBy(GroupBy[DataFrame], Generic[ByT, _TT]):
@overload
def transform(
self,
func: Callable,
*args: Any,
**kwargs: Any,
func: Callable[Concatenate[DataFrame, P], Any],
*args: P.args,
**kwargs: P.kwargs,
) -> DataFrame: ...
@overload
def transform(
self, func: TransformReductionListType, *args: Any, **kwargs: Any
) -> DataFrame: ...
def filter(
self, func: Callable, dropna: bool = ..., *args: Any, **kwargs: Any
self,
func: Callable[Concatenate[DataFrame, P], Any],
dropna: bool = ...,
*args: P.args,
**kwargs: P.kwargs,
) -> DataFrame: ...
@overload
def __getitem__(self, key: Scalar) -> SeriesGroupBy[Any, ByT]: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
Expand Down
7 changes: 6 additions & 1 deletion pandas-stubs/core/groupby/groupby.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ _ResamplerGroupBy: TypeAlias = (

class GroupBy(BaseGroupBy[NDFrameT]):
def __getattr__(self, attr: str) -> Any: ...
def apply(self, func: Callable | str, *args: Any, **kwargs: Any) -> NDFrameT: ...
def apply(
self,
func: Callable[Concatenate[NDFrameT, P], Any] | str,
*args: P.args,
**kwargs: P.kwargs,
) -> NDFrameT: ...
@final
@overload
def any(self: GroupBy[Series], skipna: bool = ...) -> Series[bool]: ...
Expand Down
5 changes: 4 additions & 1 deletion pandas-stubs/core/indexes/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,10 @@ class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]):
) -> Self: ...
def copy(self, name: Hashable = ..., deep: bool = False) -> Self: ...
def format(
self, name: bool = ..., formatter: Callable | None = ..., na_rep: _str = ...
self,
name: bool = ...,
formatter: Callable[..., Any] | None = ...,
na_rep: _str = ...,
) -> list[_str]: ...
def to_series(
self, index: Index | None = None, name: Hashable | None = None
Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/core/indexes/multi.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class MultiIndex(Index):
def format(
self,
name: bool | None = ...,
formatter: Callable | None = ...,
formatter: Callable[..., Any] | None = ...,
na_rep: str | None = ...,
names: bool = ...,
space: int = ...,
Expand Down
Loading