Skip to content

Commit d2b95e8

Browse files
committed
Callable
1 parent 13d243f commit d2b95e8

File tree

12 files changed

+58
-31
lines changed

12 files changed

+58
-31
lines changed

pandas-stubs/_libs/tslibs/timestamps.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class Timestamp(datetime, SupportsIndex):
100100
def fold(self) -> int: ...
101101
if sys.version_info >= (3, 12):
102102
@classmethod
103-
def fromtimestamp( # pyright: ignore[reportIncompatibleMethodOverride]
103+
def fromtimestamp( # pyright: ignore[reportIncompatibleMethodOverride] # ty: ignore[invalid-method-override]
104104
cls, t: float, tz: _tzinfo | str | None = ...
105105
) -> Self: ...
106106
else:

pandas-stubs/_typing.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ from typing import (
2222
SupportsIndex,
2323
TypeAlias,
2424
TypedDict,
25-
Union,
2625
overload,
2726
)
2827

@@ -596,8 +595,7 @@ IndexKeyFunc: TypeAlias = Callable[[Index], Index | AnyArrayLike] | None
596595

597596
# types of `func` kwarg for DataFrame.aggregate and Series.aggregate
598597
# More specific than what is in pandas
599-
# following Union is here to make it ty compliant https://github.com/astral-sh/ty/issues/591
600-
AggFuncTypeBase: TypeAlias = Union[Callable, str, np.ufunc] # noqa: UP007
598+
AggFuncTypeBase: TypeAlias = Callable[..., Any] | str | np.ufunc
601599
AggFuncTypeDictSeries: TypeAlias = Mapping[HashableT, AggFuncTypeBase]
602600
AggFuncTypeDictFrame: TypeAlias = Mapping[
603601
HashableT, AggFuncTypeBase | list[AggFuncTypeBase]
@@ -694,7 +692,9 @@ CompressionOptions: TypeAlias = (
694692

695693
# types in DataFrameFormatter
696694
FormattersType: TypeAlias = (
697-
list[Callable] | tuple[Callable, ...] | Mapping[str | int, Callable]
695+
list[Callable[..., Any]]
696+
| tuple[Callable[..., Any], ...]
697+
| Mapping[str | int, Callable[..., Any]]
698698
)
699699
# ColspaceType = Mapping[Hashable, Union[str, int]] not used in stubs
700700
FloatFormatType: TypeAlias = str | Callable[[float], str] | EngFormatter

pandas-stubs/core/frame.pyi

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
12781278
other: DataFrame | Series,
12791279
join: UpdateJoin = "left",
12801280
overwrite: _bool = True,
1281-
filter_func: Callable | None = ...,
1281+
filter_func: Callable[..., Any] | None = ...,
12821282
errors: IgnoreRaise = "ignore",
12831283
) -> None: ...
12841284
@overload
@@ -1684,7 +1684,10 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
16841684

16851685
# Add spacing between apply() overloads and remaining annotations
16861686
def map(
1687-
self, func: Callable, na_action: Literal["ignore"] | None = None, **kwargs: Any
1687+
self,
1688+
func: Callable[..., Any],
1689+
na_action: Literal["ignore"] | None = None,
1690+
**kwargs: Any,
16881691
) -> Self: ...
16891692
def join(
16901693
self,
@@ -2332,7 +2335,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
23322335
| Callable[[DataFrame], DataFrame]
23332336
| Callable[[Any], _bool]
23342337
),
2335-
other: Scalar | Series | DataFrame | Callable | NAType | None = ...,
2338+
other: Scalar | Series | DataFrame | Callable[..., Any] | NAType | None = ...,
23362339
*,
23372340
inplace: Literal[True],
23382341
axis: Axis | None = ...,
@@ -2349,7 +2352,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
23492352
| Callable[[DataFrame], DataFrame]
23502353
| Callable[[Any], _bool]
23512354
),
2352-
other: Scalar | Series | DataFrame | Callable | NAType | None = ...,
2355+
other: Scalar | Series | DataFrame | Callable[..., Any] | NAType | None = ...,
23532356
*,
23542357
inplace: Literal[False] = False,
23552358
axis: Axis | None = ...,
@@ -2510,8 +2513,12 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
25102513
def rename_axis(
25112514
self,
25122515
*,
2513-
index: _str | Sequence[_str] | dict[_str | int, _str] | Callable | None = ...,
2514-
columns: _str | Sequence[_str] | dict[_str | int, _str] | Callable | None = ...,
2516+
index: (
2517+
_str | Sequence[_str] | dict[_str | int, _str] | Callable[..., Any] | None
2518+
) = ...,
2519+
columns: (
2520+
_str | Sequence[_str] | dict[_str | int, _str] | Callable[..., Any] | None
2521+
) = ...,
25152522
copy: _bool = ...,
25162523
inplace: Literal[True],
25172524
) -> None: ...
@@ -2520,8 +2527,12 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
25202527
def rename_axis(
25212528
self,
25222529
*,
2523-
index: _str | Sequence[_str] | dict[_str | int, _str] | Callable | None = ...,
2524-
columns: _str | Sequence[_str] | dict[_str | int, _str] | Callable | None = ...,
2530+
index: (
2531+
_str | Sequence[_str] | dict[_str | int, _str] | Callable[..., Any] | None
2532+
) = ...,
2533+
columns: (
2534+
_str | Sequence[_str] | dict[_str | int, _str] | Callable[..., Any] | None
2535+
) = ...,
25252536
copy: _bool = ...,
25262537
inplace: Literal[False] = False,
25272538
) -> Self: ...

pandas-stubs/core/groupby/generic.pyi

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,11 @@ class SeriesGroupBy(GroupBy[Series[S2]], Generic[S2, ByT]):
118118
self, func: TransformReductionListType, *args: Any, **kwargs: Any
119119
) -> Series: ...
120120
def filter(
121-
self, func: Callable | str, dropna: bool = ..., *args: Any, **kwargs: Any
121+
self,
122+
func: Callable[..., Any] | str,
123+
dropna: bool = ...,
124+
*args: Any,
125+
**kwargs: Any,
122126
) -> Series: ...
123127
def nunique(self, dropna: bool = ...) -> Series[int]: ...
124128
# describe delegates to super() method but here it has keyword-only parameters
@@ -292,7 +296,7 @@ class DataFrameGroupBy(GroupBy[DataFrame], Generic[ByT, _TT]):
292296
self, func: TransformReductionListType, *args: Any, **kwargs: Any
293297
) -> DataFrame: ...
294298
def filter(
295-
self, func: Callable, dropna: bool = ..., *args: Any, **kwargs: Any
299+
self, func: Callable[..., Any], dropna: bool = ..., *args: Any, **kwargs: Any
296300
) -> DataFrame: ...
297301
@overload
298302
def __getitem__(self, key: Scalar) -> SeriesGroupBy[Any, ByT]: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]

pandas-stubs/core/groupby/groupby.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ _ResamplerGroupBy: TypeAlias = (
7878

7979
class GroupBy(BaseGroupBy[NDFrameT]):
8080
def __getattr__(self, attr: str) -> Any: ...
81-
def apply(self, func: Callable | str, *args: Any, **kwargs: Any) -> NDFrameT: ...
81+
def apply(
82+
self, func: Callable[..., Any] | str, *args: Any, **kwargs: Any
83+
) -> NDFrameT: ...
8284
@final
8385
@overload
8486
def any(self: GroupBy[Series], skipna: bool = ...) -> Series[bool]: ...

pandas-stubs/core/indexes/base.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,10 @@ class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]):
408408
) -> Self: ...
409409
def copy(self, name: Hashable = ..., deep: bool = False) -> Self: ...
410410
def format(
411-
self, name: bool = ..., formatter: Callable | None = ..., na_rep: _str = ...
411+
self,
412+
name: bool = ...,
413+
formatter: Callable[..., Any] | None = ...,
414+
na_rep: _str = ...,
412415
) -> list[_str]: ...
413416
def to_series(
414417
self, index: Index | None = None, name: Hashable | None = None

pandas-stubs/core/indexes/multi.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class MultiIndex(Index):
9494
def format(
9595
self,
9696
name: bool | None = ...,
97-
formatter: Callable | None = ...,
97+
formatter: Callable[..., Any] | None = ...,
9898
na_rep: str | None = ...,
9999
names: bool = ...,
100100
space: int = ...,

pandas-stubs/core/series.pyi

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
559559
def __len__(self) -> int: ...
560560
@final
561561
def __array_ufunc__(
562-
self, ufunc: Callable, method: _str, *inputs: Any, **kwargs: Any
562+
self, ufunc: Callable[..., Any], method: _str, *inputs: Any, **kwargs: Any
563563
) -> Any: ...
564564
def __array__( # ty: ignore[invalid-method-override]
565565
self, dtype: _str | np.dtype = ..., copy: bool | None = ...
@@ -1025,7 +1025,10 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
10251025
result_names: Suffixes = ...,
10261026
) -> DataFrame: ...
10271027
def combine(
1028-
self, other: Series[S1], func: Callable, fill_value: Scalar | None = ...
1028+
self,
1029+
other: Series[S1],
1030+
func: Callable[..., Any],
1031+
fill_value: Scalar | None = ...,
10291032
) -> Series[S1]: ...
10301033
def combine_first(self, other: Series[S1]) -> Series[S1]: ...
10311034
def update(self, other: Series[S1] | Sequence[S1] | Mapping[int, S1]) -> None: ...
@@ -1670,7 +1673,9 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
16701673
| Callable[[Series[S1]], Series[bool]]
16711674
| Callable[[S1], bool]
16721675
),
1673-
other: Scalar | Series[S1] | DataFrame | Callable | NAType | None = ...,
1676+
other: (
1677+
Scalar | Series[S1] | DataFrame | Callable[..., Any] | NAType | None
1678+
) = ...,
16741679
*,
16751680
inplace: Literal[True],
16761681
axis: AxisIndex | None = 0,
@@ -1686,7 +1691,9 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
16861691
| Callable[[Series[S1]], Series[bool]]
16871692
| Callable[[S1], bool]
16881693
),
1689-
other: Scalar | Series[S1] | DataFrame | Callable | NAType | None = ...,
1694+
other: (
1695+
Scalar | Series[S1] | DataFrame | Callable[..., Any] | NAType | None
1696+
) = ...,
16901697
*,
16911698
inplace: Literal[False] = False,
16921699
axis: AxisIndex | None = 0,
@@ -4631,7 +4638,7 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
46314638
def rename_axis(
46324639
self,
46334640
*,
4634-
index: Scalar | ListLike | Callable | dict | None = ...,
4641+
index: Scalar | ListLike | Callable[..., Any] | dict | None = ...,
46354642
copy: _bool = ...,
46364643
inplace: Literal[True],
46374644
) -> None: ...
@@ -4640,7 +4647,7 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
46404647
def rename_axis(
46414648
self,
46424649
*,
4643-
index: Scalar | ListLike | Callable | dict | None = ...,
4650+
index: Scalar | ListLike | Callable[..., Any] | dict | None = ...,
46444651
copy: _bool = ...,
46454652
inplace: Literal[False] = False,
46464653
) -> Self: ...

pandas-stubs/io/clipboards.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def read_clipboard(
5959
) = ...,
6060
infer_datetime_format: bool = ...,
6161
keep_date_col: bool = ...,
62-
date_parser: Callable = ...,
62+
date_parser: Callable[..., Any] = ...,
6363
dayfirst: bool = ...,
6464
cache_dates: bool = ...,
6565
iterator: Literal[True],
@@ -118,7 +118,7 @@ def read_clipboard(
118118
) = ...,
119119
infer_datetime_format: bool = ...,
120120
keep_date_col: bool = ...,
121-
date_parser: Callable = ...,
121+
date_parser: Callable[..., Any] = ...,
122122
dayfirst: bool = ...,
123123
cache_dates: bool = ...,
124124
iterator: bool = ...,
@@ -177,7 +177,7 @@ def read_clipboard(
177177
) = ...,
178178
infer_datetime_format: bool = ...,
179179
keep_date_col: bool = ...,
180-
date_parser: Callable = ...,
180+
date_parser: Callable[..., Any] = ...,
181181
dayfirst: bool = ...,
182182
cache_dates: bool = ...,
183183
iterator: Literal[False] = False,

pandas-stubs/io/excel/_base.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ class ExcelFile:
276276
| Sequence[Sequence[str] | Sequence[int]]
277277
| dict[str, Sequence[int] | list[str]]
278278
) = ...,
279-
date_parser: Callable | None = ...,
279+
date_parser: Callable[..., Any] | None = ...,
280280
thousands: str | None = ...,
281281
comment: str | None = ...,
282282
skipfooter: int = ...,
@@ -304,7 +304,7 @@ class ExcelFile:
304304
| Sequence[Sequence[str] | Sequence[int]]
305305
| dict[str, Sequence[int] | list[str]]
306306
) = ...,
307-
date_parser: Callable | None = ...,
307+
date_parser: Callable[..., Any] | None = ...,
308308
thousands: str | None = ...,
309309
comment: str | None = ...,
310310
skipfooter: int = ...,

0 commit comments

Comments
 (0)