Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
TYP: Add second HashableT
  • Loading branch information
Kevin Sheppard committed Oct 7, 2022
commit 5c97c6dd0cbe9fa38b7484f1b3b84b250d495918
6 changes: 5 additions & 1 deletion pandas-stubs/core/reshape/pivot.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from typing import (
Callable,
Hashable,
Literal,
Sequence,
TypeVar,
)

import numpy as np
Expand All @@ -16,6 +18,8 @@ from pandas._typing import (
npt,
)

_HashableT2 = TypeVar("_HashableT2", bound=Hashable)

def pivot_table(
data: DataFrame,
values: str | None = ...,
Expand All @@ -40,7 +44,7 @@ def crosstab(
columns: list | npt.NDArray | Series | list[Sequence | npt.NDArray | Series],
values: list | npt.NDArray | Series | None = ...,
rownames: list[HashableT] | None = ...,
colnames: list[HashableT] | None = ...,
colnames: list[_HashableT2] | None = ...,
aggfunc: str | np.ufunc | Callable[[Series], float] | None = ...,
margins: bool = ...,
margins_name: str = ...,
Expand Down
3 changes: 1 addition & 2 deletions tests/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,10 @@ def m2(x: pd.Series) -> int:
)
rownames: list[tuple] = [("b", 1)]
colnames: list[tuple] = [("a",)]
# pyright can't figure out that these are hashable
check(
assert_type(
pd.crosstab(a, b, colnames=colnames, rownames=rownames),
pd.DataFrame, # pyright: ignore
pd.DataFrame,
),
pd.DataFrame,
)
Expand Down