Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove HashableT in frame.pyi where possible #1104

Merged
merged 3 commits into from
Feb 4, 2025
Merged
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
59 changes: 34 additions & 25 deletions pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ from pandas._typing import (
HashableT,
HashableT1,
HashableT2,
HashableT3,
IgnoreRaise,
IndexingInt,
IndexLabel,
Expand Down Expand Up @@ -175,13 +174,13 @@ class _LocIndexerFrame(_LocIndexer, Generic[_T]):
@overload
def __getitem__(self, idx: Scalar) -> Series | _T: ...
@overload
def __getitem__(
def __getitem__( # type: ignore[overload-overlap]
self,
idx: (
IndexType
| MaskType
| Callable[[DataFrame], IndexType | MaskType | list[HashableT]]
| list[HashableT]
| Callable[[DataFrame], IndexType | MaskType | Sequence[Hashable]]
| list[Hashable]
| tuple[
IndexType
| MaskType
Expand Down Expand Up @@ -236,7 +235,7 @@ class _LocIndexerFrame(_LocIndexer, Generic[_T]):
@overload
def __setitem__(
self,
idx: tuple[_IndexSliceTuple, HashableT],
idx: tuple[_IndexSliceTuple, Hashable],
value: Scalar | NAType | NaTType | ArrayLike | Series | list | None,
) -> None: ...

Expand Down Expand Up @@ -432,10 +431,10 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
self,
index: _bool = ...,
column_dtypes: (
_str | npt.DTypeLike | Mapping[HashableT1, npt.DTypeLike] | None
_str | npt.DTypeLike | Mapping[Hashable, npt.DTypeLike] | None
) = ...,
index_dtypes: (
_str | npt.DTypeLike | Mapping[HashableT2, npt.DTypeLike] | None
_str | npt.DTypeLike | Mapping[Hashable, npt.DTypeLike] | None
) = ...,
) -> np.recarray: ...
def to_stata(
Expand All @@ -449,7 +448,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
data_label: _str | None = ...,
variable_labels: dict[HashableT2, str] | None = ...,
version: Literal[114, 117, 118, 119] | None = ...,
convert_strl: list[HashableT3] | None = ...,
convert_strl: list[Hashable] | None = ...,
compression: CompressionOptions = ...,
storage_options: StorageOptions = ...,
value_labels: dict[Hashable, dict[float, str]] | None = ...,
Expand All @@ -462,7 +461,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
engine: ParquetEngine = ...,
compression: Literal["snappy", "gzip", "brotli", "lz4", "zstd"] | None = ...,
index: bool | None = ...,
partition_cols: list[HashableT] | None = ...,
partition_cols: Sequence[Hashable] | None = ...,
storage_options: StorageOptions = ...,
**kwargs: Any,
) -> None: ...
Expand All @@ -473,7 +472,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
engine: ParquetEngine = ...,
compression: Literal["snappy", "gzip", "brotli", "lz4", "zstd"] | None = ...,
index: bool | None = ...,
partition_cols: list[HashableT] | None = ...,
partition_cols: Sequence[Hashable] | None = ...,
storage_options: StorageOptions = ...,
**kwargs: Any,
) -> bytes: ...
Expand All @@ -499,7 +498,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
def to_html(
self,
buf: FilePath | WriteBuffer[str],
columns: list[HashableT] | Index | Series | None = ...,
columns: list[Hashable] | Index | Series | None = ...,
col_space: ColspaceArgType | None = ...,
header: _bool = ...,
index: _bool = ...,
Expand Down Expand Up @@ -546,7 +545,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
def to_html(
self,
buf: None = ...,
columns: Sequence[HashableT] | None = ...,
columns: Sequence[Hashable] | None = ...,
col_space: ColspaceArgType | None = ...,
header: _bool = ...,
index: _bool = ...,
Expand Down Expand Up @@ -597,8 +596,8 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
root_name: str = ...,
row_name: str = ...,
na_rep: str | None = ...,
attr_cols: list[HashableT1] | None = ...,
elem_cols: list[HashableT2] | None = ...,
attr_cols: list[Hashable] | None = ...,
elem_cols: list[Hashable] | None = ...,
namespaces: dict[str | None, str] | None = ...,
prefix: str | None = ...,
encoding: str = ...,
Expand All @@ -617,8 +616,8 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
root_name: str | None = ...,
row_name: str | None = ...,
na_rep: str | None = ...,
attr_cols: list[HashableT1] | None = ...,
elem_cols: list[HashableT2] | None = ...,
attr_cols: list[Hashable] | None = ...,
elem_cols: list[Hashable] | None = ...,
namespaces: dict[str | None, str] | None = ...,
prefix: str | None = ...,
encoding: str = ...,
Expand Down Expand Up @@ -846,7 +845,12 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
def set_index(
self,
keys: (
Label | Series | Index | np.ndarray | Iterator[HashableT] | list[HashableT]
Label
| Series
| Index
| np.ndarray
| Iterator[Hashable]
| Sequence[Hashable]
),
*,
drop: _bool = ...,
Expand All @@ -858,7 +862,12 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
def set_index(
self,
keys: (
Label | Series | Index | np.ndarray | Iterator[HashableT] | list[HashableT]
Label
| Series
| Index
| np.ndarray
| Iterator[Hashable]
| Sequence[Hashable]
),
*,
drop: _bool = ...,
Expand All @@ -876,7 +885,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
col_fill: Hashable = ...,
inplace: Literal[True],
allow_duplicates: _bool = ...,
names: Hashable | list[HashableT] = ...,
names: Hashable | Sequence[Hashable] = ...,
) -> None: ...
@overload
def reset_index(
Expand All @@ -888,7 +897,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
drop: _bool = ...,
inplace: Literal[False] = ...,
allow_duplicates: _bool = ...,
names: Hashable | list[HashableT] = ...,
names: Hashable | Sequence[Hashable] = ...,
) -> Self: ...
@overload
def reset_index(
Expand All @@ -900,7 +909,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
col_level: int | _str = ...,
col_fill: Hashable = ...,
allow_duplicates: _bool = ...,
names: Hashable | list[HashableT] = ...,
names: Hashable | Sequence[Hashable] = ...,
) -> Self | None: ...
def isna(self) -> Self: ...
def isnull(self) -> Self: ...
Expand Down Expand Up @@ -1681,7 +1690,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
def columns(self) -> Index[str]: ...
@columns.setter # setter needs to be right next to getter; otherwise mypy complains
def columns(
self, cols: AnyArrayLike | list[HashableT] | tuple[HashableT, ...]
self, cols: AnyArrayLike | list[Hashable] | tuple[Hashable, ...]
) -> None: ...
@property
def dtypes(self) -> Series: ...
Expand Down Expand Up @@ -2359,8 +2368,8 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
def to_string(
self,
buf: FilePath | WriteBuffer[str],
columns: list[HashableT1] | Index | Series | None = ...,
col_space: int | list[int] | dict[HashableT2, int] | None = ...,
columns: Sequence[Hashable] | Index | Series | None = ...,
col_space: int | list[int] | dict[Hashable, int] | None = ...,
header: _bool | list[_str] | tuple[str, ...] = ...,
index: _bool = ...,
na_rep: _str = ...,
Expand All @@ -2382,7 +2391,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
def to_string(
self,
buf: None = ...,
columns: list[HashableT] | Index | Series | None = ...,
columns: Sequence[Hashable] | Index | Series | None = ...,
col_space: int | list[int] | dict[Hashable, int] | None = ...,
header: _bool | Sequence[_str] = ...,
index: _bool = ...,
Expand Down