Skip to content

Commit 0a7a65f

Browse files
committed
cut, pivot_table
1 parent 4367945 commit 0a7a65f

File tree

6 files changed

+36
-39
lines changed

6 files changed

+36
-39
lines changed

pandas-stubs/__init__.pyi

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ from pandas.core.computation.api import eval as eval
7070
from pandas.core.reshape.api import (
7171
concat as concat,
7272
crosstab as crosstab,
73+
cut as cut,
7374
from_dummies as from_dummies,
7475
get_dummies as get_dummies,
7576
lreshape as lreshape,
@@ -78,15 +79,10 @@ from pandas.core.reshape.api import (
7879
merge_asof as merge_asof,
7980
merge_ordered as merge_ordered,
8081
pivot as pivot,
82+
pivot_table as pivot_table,
8183
qcut as qcut,
8284
wide_to_long as wide_to_long,
8385
)
84-
from pandas.core.reshape.api import (
85-
cut as cut, # pyright: ignore[reportUnknownVariableType]
86-
)
87-
from pandas.core.reshape.api import (
88-
pivot_table as pivot_table, # pyright: ignore[reportUnknownVariableType]
89-
)
9086

9187
from pandas._config import (
9288
describe_option as describe_option,

pandas-stubs/core/frame.pyi

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ from pandas.core.indexing import (
5757
_LocIndexer,
5858
)
5959
from pandas.core.reshape.pivot import (
60-
_PivotAggFunc, # pyright: ignore[reportUnknownVariableType]
61-
)
62-
from pandas.core.reshape.pivot import (
60+
_PivotAggFunc,
6361
_PivotTableColumnsTypes,
6462
_PivotTableIndexTypes,
6563
_PivotTableValuesTypes,

pandas-stubs/core/reshape/api.pyi

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,11 @@ from pandas.core.reshape.merge import (
1414
merge_ordered as merge_ordered,
1515
)
1616
from pandas.core.reshape.pivot import (
17-
crosstab as crosstab, # pyright: ignore[reportUnknownVariableType]
18-
)
19-
from pandas.core.reshape.pivot import (
17+
crosstab as crosstab,
2018
pivot as pivot,
21-
)
22-
from pandas.core.reshape.pivot import (
23-
pivot_table as pivot_table, # pyright: ignore[reportUnknownVariableType]
24-
)
25-
from pandas.core.reshape.tile import (
26-
cut as cut, # pyright: ignore[reportUnknownVariableType]
19+
pivot_table as pivot_table,
2720
)
2821
from pandas.core.reshape.tile import (
22+
cut as cut,
2923
qcut as qcut,
3024
)

pandas-stubs/core/reshape/pivot.pyi

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ from pandas._typing import (
3434

3535
_PivotAggCallable: TypeAlias = Callable[[Series], ScalarT]
3636

37-
_PivotAggFunc: TypeAlias = ( # pyright: ignore[reportUnknownVariableType]
38-
_PivotAggCallable
37+
_PivotAggFunc: TypeAlias = (
38+
_PivotAggCallable[ScalarT]
3939
| np.ufunc
4040
| Literal["mean", "sum", "count", "min", "max", "median", "std", "var"]
4141
)
@@ -66,11 +66,13 @@ _ExtendedAnyArrayLike: TypeAlias = AnyArrayLike | ArrayLike
6666
@overload
6767
def pivot_table(
6868
data: DataFrame,
69-
values: _PivotTableValuesTypes = None,
70-
index: _PivotTableIndexTypes = None,
71-
columns: _PivotTableColumnsTypes = None,
69+
values: _PivotTableValuesTypes[Hashable] = None,
70+
index: _PivotTableIndexTypes[Hashable] = None,
71+
columns: _PivotTableColumnsTypes[Hashable] = None,
7272
aggfunc: (
73-
_PivotAggFunc | Sequence[_PivotAggFunc] | Mapping[Hashable, _PivotAggFunc]
73+
_PivotAggFunc[Any]
74+
| Sequence[_PivotAggFunc[Any]]
75+
| Mapping[Hashable, _PivotAggFunc[Any]]
7476
) = "mean",
7577
fill_value: Scalar | None = None,
7678
margins: bool = False,
@@ -84,12 +86,14 @@ def pivot_table(
8486
@overload
8587
def pivot_table(
8688
data: DataFrame,
87-
values: _PivotTableValuesTypes = None,
89+
values: _PivotTableValuesTypes[Hashable] = None,
8890
*,
8991
index: Grouper,
90-
columns: _PivotTableColumnsTypes | np_ndarray | Index[Any] = None,
92+
columns: _PivotTableColumnsTypes[Hashable] | np_ndarray | Index[Any] = None,
9193
aggfunc: (
92-
_PivotAggFunc | Sequence[_PivotAggFunc] | Mapping[Hashable, _PivotAggFunc]
94+
_PivotAggFunc[Any]
95+
| Sequence[_PivotAggFunc[Any]]
96+
| Mapping[Hashable, _PivotAggFunc[Any]]
9397
) = "mean",
9498
fill_value: Scalar | None = None,
9599
margins: bool = False,
@@ -101,12 +105,14 @@ def pivot_table(
101105
@overload
102106
def pivot_table(
103107
data: DataFrame,
104-
values: _PivotTableValuesTypes = None,
105-
index: _PivotTableIndexTypes | np_ndarray | Index[Any] = None,
108+
values: _PivotTableValuesTypes[Hashable] = None,
109+
index: _PivotTableIndexTypes[Hashable] | np_ndarray | Index[Any] = None,
106110
*,
107111
columns: Grouper,
108112
aggfunc: (
109-
_PivotAggFunc | Sequence[_PivotAggFunc] | Mapping[Hashable, _PivotAggFunc]
113+
_PivotAggFunc[Any]
114+
| Sequence[_PivotAggFunc[Any]]
115+
| Mapping[Hashable, _PivotAggFunc[Any]]
110116
) = "mean",
111117
fill_value: Scalar | None = None,
112118
margins: bool = False,

pandas-stubs/core/reshape/tile.pyi

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from collections.abc import Sequence
22
from typing import (
3+
Any,
34
Literal,
45
overload,
56
)
@@ -102,7 +103,7 @@ def cut(
102103
include_lowest: bool = ...,
103104
duplicates: Literal["raise", "drop"] = ...,
104105
ordered: bool = ...,
105-
) -> tuple[Series, IntervalIndex]: ...
106+
) -> tuple[Series, IntervalIndex[Any]]: ...
106107
@overload
107108
def cut(
108109
x: Sequence[float] | np_ndarray_anyint | np_ndarray_float | Index,
@@ -132,7 +133,9 @@ def cut(
132133
@overload
133134
def cut(
134135
x: Sequence[float] | np_ndarray_anyint | np_ndarray_float | Index,
135-
bins: int | Sequence[float] | Index[int] | Index[float] | IntervalIndex | Series,
136+
bins: (
137+
int | Sequence[float] | Index[int] | Index[float] | IntervalIndex[Any] | Series
138+
),
136139
right: bool = ...,
137140
*,
138141
labels: Literal[False],
@@ -163,7 +166,9 @@ def cut(
163166
@overload
164167
def cut(
165168
x: Series,
166-
bins: int | Sequence[float] | Index[int] | Index[float] | IntervalIndex | Series,
169+
bins: (
170+
int | Sequence[float] | Index[int] | Index[float] | IntervalIndex[Any] | Series
171+
),
167172
right: bool = ...,
168173
labels: Literal[False] | Sequence[Label] | None = ...,
169174
retbins: Literal[False] = False,
@@ -175,7 +180,9 @@ def cut(
175180
@overload
176181
def cut(
177182
x: Sequence[float] | np_ndarray_anyint | np_ndarray_float | Index,
178-
bins: int | Sequence[float] | Index[int] | Index[float] | IntervalIndex | Series,
183+
bins: (
184+
int | Sequence[float] | Index[int] | Index[float] | IntervalIndex[Any] | Series
185+
),
179186
right: bool = ...,
180187
labels: Sequence[Label] | None = ...,
181188
retbins: Literal[False] = False,

tests/test_pandas.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,11 +1026,7 @@ def test_cut() -> None:
10261026
labels=["1", "2", "3", "4"],
10271027
retbins=True,
10281028
)
1029-
m0, m1 = pd.cut( # pyright: ignore[reportUnknownVariableType]
1030-
pd.Series([1, 2, 3, 4, 5, 6, 7, 8]),
1031-
intval_idx,
1032-
retbins=True,
1033-
)
1029+
m0, m1 = pd.cut(pd.Series([1, 2, 3, 4, 5, 6, 7, 8]), intval_idx, retbins=True)
10341030
check(assert_type(j0, pd.Series), pd.Series)
10351031
check(assert_type(j1, np_1darray_float), np_1darray, np.floating)
10361032
check(assert_type(k0, pd.Series), pd.Series)

0 commit comments

Comments
 (0)