Skip to content

Commit da82bc7

Browse files
twoertweinyehoshuadimarsky
authored andcommitted
TYP: fix some of the __hash__ methods (pandas-dev#47654)
1 parent 4436972 commit da82bc7

File tree

6 files changed

+11
-7
lines changed

6 files changed

+11
-7
lines changed

pandas/core/arrays/arrow/_arrow_utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def __eq__(self, other):
9292
else:
9393
return NotImplemented
9494

95-
def __hash__(self):
95+
def __hash__(self) -> int:
9696
return hash((str(self), self.freq))
9797

9898
def to_pandas_dtype(self):
@@ -158,7 +158,7 @@ def __eq__(self, other):
158158
else:
159159
return NotImplemented
160160

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

164164
def to_pandas_dtype(self):

pandas/core/arrays/base.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
TYPE_CHECKING,
1515
Any,
1616
Callable,
17+
ClassVar,
1718
Iterator,
1819
Literal,
1920
Sequence,
@@ -1442,7 +1443,7 @@ def _reduce(self, name: str, *, skipna: bool = True, **kwargs):
14421443
# https://github.com/python/typeshed/issues/2148#issuecomment-520783318
14431444
# Incompatible types in assignment (expression has type "None", base class
14441445
# "object" defined the type as "Callable[[object], int]")
1445-
__hash__: None # type: ignore[assignment]
1446+
__hash__: ClassVar[None] # type: ignore[assignment]
14461447

14471448
# ------------------------------------------------------------------------
14481449
# Non-Optimized Default Methods; in the case of the private methods here,

pandas/core/arrays/sparse/dtype.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def __init__(self, dtype: Dtype = np.float64, fill_value: Any = None) -> None:
9999
self._fill_value = fill_value
100100
self._check_fill_value()
101101

102-
def __hash__(self):
102+
def __hash__(self) -> int:
103103
# Python3 doesn't inherit __hash__ when a base class overrides
104104
# __eq__, so we explicitly do it here.
105105
return super().__hash__()

pandas/core/generic.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
TYPE_CHECKING,
1414
Any,
1515
Callable,
16+
ClassVar,
1617
Hashable,
1718
Literal,
1819
Mapping,
@@ -1882,7 +1883,7 @@ def _drop_labels_or_levels(self, keys, axis: int = 0):
18821883
# https://github.com/python/typeshed/issues/2148#issuecomment-520783318
18831884
# Incompatible types in assignment (expression has type "None", base class
18841885
# "object" defined the type as "Callable[[object], int]")
1885-
__hash__: None # type: ignore[assignment]
1886+
__hash__: ClassVar[None] # type: ignore[assignment]
18861887

18871888
def __iter__(self):
18881889
"""

pandas/core/indexes/base.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
TYPE_CHECKING,
99
Any,
1010
Callable,
11+
ClassVar,
1112
Hashable,
1213
Iterable,
1314
Literal,
@@ -5296,7 +5297,7 @@ def __contains__(self, key: Any) -> bool:
52965297
# https://github.com/python/typeshed/issues/2148#issuecomment-520783318
52975298
# Incompatible types in assignment (expression has type "None", base class
52985299
# "object" defined the type as "Callable[[object], int]")
5299-
__hash__: None # type: ignore[assignment]
5300+
__hash__: ClassVar[None] # type: ignore[assignment]
53005301

53015302
@final
53025303
def __setitem__(self, key, value):

pandas/core/indexes/frozen.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ def __mul__(self, other):
8989
def __reduce__(self):
9090
return type(self), (list(self),)
9191

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

9596
def _disabled(self, *args, **kwargs):

0 commit comments

Comments
 (0)