Skip to content

Commit 435cf0e

Browse files
committed
missing cases
1 parent 92abc90 commit 435cf0e

File tree

5 files changed

+41
-25
lines changed

5 files changed

+41
-25
lines changed

pandas-stubs/_typing.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ Level: TypeAlias = Hashable
182182
Shape: TypeAlias = tuple[int, ...]
183183
Suffixes: TypeAlias = tuple[str | None, str | None] | list[str | None]
184184
Ordered: TypeAlias = bool | None
185-
JSONSerializable: TypeAlias = PythonScalar | list[Any] | dict
185+
JSONSerializable: TypeAlias = PythonScalar | list[Any] | dict[str, Any]
186186
Frequency: TypeAlias = str | BaseOffset
187187
PeriodFrequency: TypeAlias = (
188188
str

pandas-stubs/core/reshape/pivot.pyi

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ from pandas._typing import (
3535
_PivotAggCallable: TypeAlias = Callable[[Series], ScalarT]
3636

3737
_PivotAggFunc: TypeAlias = (
38-
_PivotAggCallable
38+
_PivotAggCallable[ScalarT]
3939
| np.ufunc
4040
| Literal["mean", "sum", "count", "min", "max", "median", "std", "var"]
4141
)
@@ -67,11 +67,17 @@ _Values: TypeAlias = SequenceNotStr[Any] | _ExtendedAnyArrayLike
6767
@overload
6868
def pivot_table(
6969
data: DataFrame,
70-
values: _PivotTableValuesTypes = None,
71-
index: _PivotTableIndexTypes = None,
72-
columns: _PivotTableColumnsTypes = None,
70+
values: _PivotTableValuesTypes[
71+
Hashable # ty: ignore[invalid-type-arguments]
72+
] = None,
73+
index: _PivotTableIndexTypes[Hashable] = None, # ty: ignore[invalid-type-arguments]
74+
columns: _PivotTableColumnsTypes[
75+
Hashable # ty: ignore[invalid-type-arguments]
76+
] = None,
7377
aggfunc: (
74-
_PivotAggFunc | Sequence[_PivotAggFunc] | Mapping[Hashable, _PivotAggFunc]
78+
_PivotAggFunc[Scalar]
79+
| Sequence[_PivotAggFunc[Scalar]]
80+
| Mapping[Hashable, _PivotAggFunc[Scalar]]
7581
) = "mean",
7682
fill_value: Scalar | None = None,
7783
margins: bool = False,
@@ -85,12 +91,20 @@ def pivot_table(
8591
@overload
8692
def pivot_table(
8793
data: DataFrame,
88-
values: _PivotTableValuesTypes = None,
94+
values: _PivotTableValuesTypes[
95+
Hashable # ty: ignore[invalid-type-arguments]
96+
] = None,
8997
*,
9098
index: Grouper,
91-
columns: _PivotTableColumnsTypes | np_ndarray | Index[Any] = None,
99+
columns: (
100+
_PivotTableColumnsTypes[Hashable] # ty: ignore[invalid-type-arguments]
101+
| np_ndarray
102+
| Index[Any]
103+
) = None,
92104
aggfunc: (
93-
_PivotAggFunc | Sequence[_PivotAggFunc] | Mapping[Hashable, _PivotAggFunc]
105+
_PivotAggFunc[Scalar]
106+
| Sequence[_PivotAggFunc[Scalar]]
107+
| Mapping[Hashable, _PivotAggFunc[Scalar]]
94108
) = "mean",
95109
fill_value: Scalar | None = None,
96110
margins: bool = False,
@@ -102,12 +116,20 @@ def pivot_table(
102116
@overload
103117
def pivot_table(
104118
data: DataFrame,
105-
values: _PivotTableValuesTypes = None,
106-
index: _PivotTableIndexTypes | np_ndarray | Index[Any] = None,
119+
values: _PivotTableValuesTypes[
120+
Hashable # ty: ignore[invalid-type-arguments]
121+
] = None,
122+
index: (
123+
_PivotTableIndexTypes[Hashable] # ty: ignore[invalid-type-arguments]
124+
| np_ndarray
125+
| Index[Any]
126+
) = None,
107127
*,
108128
columns: Grouper,
109129
aggfunc: (
110-
_PivotAggFunc | Sequence[_PivotAggFunc] | Mapping[Hashable, _PivotAggFunc]
130+
_PivotAggFunc[Scalar]
131+
| Sequence[_PivotAggFunc[Scalar]]
132+
| Mapping[Hashable, _PivotAggFunc[Scalar]]
111133
) = "mean",
112134
fill_value: Scalar | None = None,
113135
margins: bool = False,

pandas-stubs/core/series.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
776776
def to_dict(self, *, into: type[dict] = ...) -> dict[Any, S1]: ...
777777
@overload
778778
def to_dict(
779-
self, *, into: type[MutableMapping] | MutableMapping
779+
self, *, into: type[MutableMapping] | MutableMapping[Hashable, Any]
780780
) -> MutableMapping[Hashable, S1]: ...
781781
def to_frame(self, name: object | None = ...) -> DataFrame: ...
782782
@overload

pandas-stubs/core/tools/timedeltas.pyi

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from collections.abc import Sequence
21
from datetime import timedelta
32
from typing import overload
43

@@ -28,14 +27,7 @@ def to_timedelta(
2827
) -> Series[Timedelta]: ...
2928
@overload
3029
def to_timedelta(
31-
arg: (
32-
SequenceNotStr
33-
| Sequence[float | timedelta]
34-
| tuple[str | float | timedelta, ...]
35-
| range
36-
| ArrayLike
37-
| Index
38-
),
30+
arg: SequenceNotStr[str | float | timedelta] | range | ArrayLike | Index,
3931
unit: TimeDeltaUnitChoices | None = ...,
4032
errors: RaiseCoerce = ...,
4133
) -> TimedeltaIndex: ...

tests/test_frame.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3991,10 +3991,10 @@ def test_to_dict_into_defaultdict() -> None:
39913991
"""Test DataFrame.to_dict with `into` is an instance of defaultdict[Any, list]"""
39923992

39933993
data = pd.DataFrame({("str", "rts"): [[1, 2, 4], [2, 3], [3]]})
3994-
target: defaultdict[Any, list] = defaultdict(list)
3994+
target: defaultdict[Hashable, list[Any]] = defaultdict(list)
39953995

39963996
check(
3997-
assert_type(data.to_dict(into=target), defaultdict[Any, list]),
3997+
assert_type(data.to_dict(into=target), defaultdict[Hashable, list[Any]]),
39983998
defaultdict,
39993999
tuple,
40004000
)
@@ -4011,7 +4011,9 @@ def test_to_dict_into_defaultdict() -> None:
40114011
str,
40124012
)
40134013
check(
4014-
assert_type(data.to_dict("records", into=target), list[defaultdict[Any, list]]),
4014+
assert_type(
4015+
data.to_dict("records", into=target), list[defaultdict[Hashable, list[Any]]]
4016+
),
40154017
list,
40164018
defaultdict,
40174019
)

0 commit comments

Comments
 (0)