Skip to content

TYP: fix some of the __hash__ methods #47654

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

Merged
merged 1 commit into from
Jul 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions pandas/core/arrays/arrow/_arrow_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def __eq__(self, other):
else:
return NotImplemented

def __hash__(self):
def __hash__(self) -> int:
return hash((str(self), self.freq))

def to_pandas_dtype(self):
Expand Down Expand Up @@ -158,7 +158,7 @@ def __eq__(self, other):
else:
return NotImplemented

def __hash__(self):
def __hash__(self) -> int:
return hash((str(self), str(self.subtype), self.inclusive))

def to_pandas_dtype(self):
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
TYPE_CHECKING,
Any,
Callable,
ClassVar,
Iterator,
Literal,
Sequence,
Expand Down Expand Up @@ -1442,7 +1443,7 @@ def _reduce(self, name: str, *, skipna: bool = True, **kwargs):
# https://github.com/python/typeshed/issues/2148#issuecomment-520783318
# Incompatible types in assignment (expression has type "None", base class
# "object" defined the type as "Callable[[object], int]")
__hash__: None # type: ignore[assignment]
__hash__: ClassVar[None] # type: ignore[assignment]

# ------------------------------------------------------------------------
# Non-Optimized Default Methods; in the case of the private methods here,
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/sparse/dtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def __init__(self, dtype: Dtype = np.float64, fill_value: Any = None) -> None:
self._fill_value = fill_value
self._check_fill_value()

def __hash__(self):
def __hash__(self) -> int:
# Python3 doesn't inherit __hash__ when a base class overrides
# __eq__, so we explicitly do it here.
return super().__hash__()
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
TYPE_CHECKING,
Any,
Callable,
ClassVar,
Hashable,
Literal,
Mapping,
Expand Down Expand Up @@ -1882,7 +1883,7 @@ def _drop_labels_or_levels(self, keys, axis: int = 0):
# https://github.com/python/typeshed/issues/2148#issuecomment-520783318
# Incompatible types in assignment (expression has type "None", base class
# "object" defined the type as "Callable[[object], int]")
__hash__: None # type: ignore[assignment]
__hash__: ClassVar[None] # type: ignore[assignment]

def __iter__(self):
"""
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
TYPE_CHECKING,
Any,
Callable,
ClassVar,
Hashable,
Iterable,
Literal,
Expand Down Expand Up @@ -5296,7 +5297,7 @@ def __contains__(self, key: Any) -> bool:
# https://github.com/python/typeshed/issues/2148#issuecomment-520783318
# Incompatible types in assignment (expression has type "None", base class
# "object" defined the type as "Callable[[object], int]")
__hash__: None # type: ignore[assignment]
__hash__: ClassVar[None] # type: ignore[assignment]

@final
def __setitem__(self, key, value):
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/indexes/frozen.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ def __mul__(self, other):
def __reduce__(self):
return type(self), (list(self),)

def __hash__(self):
# error: Signature of "__hash__" incompatible with supertype "list"
def __hash__(self) -> int: # type: ignore[override]
return hash(tuple(self))

def _disabled(self, *args, **kwargs):
Expand Down