Skip to content

Commit f03d78c

Browse files
ShaharNavehproost
authored andcommitted
TYP: Added typing to __eq__ functions (pandas-dev#29818)
1 parent 84bc45e commit f03d78c

File tree

11 files changed

+14
-14
lines changed

11 files changed

+14
-14
lines changed

pandas/_libs/tslibs/offsets.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ class _BaseOffset:
328328
def __setattr__(self, name, value):
329329
raise AttributeError("DateOffset objects are immutable.")
330330

331-
def __eq__(self, other):
331+
def __eq__(self, other) -> bool:
332332
if isinstance(other, str):
333333
try:
334334
# GH#23524 if to_offset fails, we are dealing with an

pandas/core/arrays/sparse/dtype.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def __hash__(self):
9090
# __eq__, so we explicitly do it here.
9191
return super().__hash__()
9292

93-
def __eq__(self, other):
93+
def __eq__(self, other) -> bool:
9494
# We have to override __eq__ to handle NA values in _metadata.
9595
# The base class does simple == checks, which fail for NA.
9696
if isinstance(other, str):

pandas/core/dtypes/dtypes.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ def __hash__(self) -> int:
765765
# TODO: update this.
766766
return hash(str(self))
767767

768-
def __eq__(self, other):
768+
def __eq__(self, other) -> bool:
769769
if isinstance(other, str):
770770
return other == self.name
771771

@@ -904,7 +904,7 @@ def __hash__(self) -> int:
904904
# make myself hashable
905905
return hash(str(self))
906906

907-
def __eq__(self, other):
907+
def __eq__(self, other) -> bool:
908908
if isinstance(other, str):
909909
return other == self.name or other == self.name.title()
910910

@@ -1077,7 +1077,7 @@ def __hash__(self) -> int:
10771077
# make myself hashable
10781078
return hash(str(self))
10791079

1080-
def __eq__(self, other):
1080+
def __eq__(self, other) -> bool:
10811081
if isinstance(other, str):
10821082
return other.lower() in (self.name.lower(), str(self).lower())
10831083
elif not isinstance(other, IntervalDtype):

pandas/core/indexes/frozen.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def __radd__(self, other):
7777
other = list(other)
7878
return self.__class__(other + list(self))
7979

80-
def __eq__(self, other):
80+
def __eq__(self, other) -> bool:
8181
if isinstance(other, (tuple, FrozenList)):
8282
other = list(other)
8383
return super().__eq__(other)

pandas/io/pytables.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2092,7 +2092,7 @@ def __repr__(self) -> str:
20922092
)
20932093
)
20942094

2095-
def __eq__(self, other):
2095+
def __eq__(self, other) -> bool:
20962096
""" compare 2 col items """
20972097
return all(
20982098
getattr(self, a, None) == getattr(other, a, None)

pandas/io/stata.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ def __repr__(self) -> str:
859859
# not perfect :-/
860860
return "{cls}({obj})".format(cls=self.__class__, obj=self)
861861

862-
def __eq__(self, other):
862+
def __eq__(self, other) -> bool:
863863
return (
864864
isinstance(other, self.__class__)
865865
and self.string == other.string

pandas/tests/indexing/test_indexing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ def __str__(self) -> str:
595595

596596
__repr__ = __str__
597597

598-
def __eq__(self, other):
598+
def __eq__(self, other) -> bool:
599599
return self.value == other.value
600600

601601
def view(self):

pandas/tests/scalar/timestamp/test_comparisons.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ def __gt__(self, o):
179179
def __ge__(self, o):
180180
return True
181181

182-
def __eq__(self, o):
183-
return isinstance(o, Inf)
182+
def __eq__(self, other) -> bool:
183+
return isinstance(other, Inf)
184184

185185
inf = Inf()
186186
timestamp = Timestamp("2018-11-30")

pandas/tests/series/test_ufunc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def __add__(self, other):
282282
other = getattr(other, "value", other)
283283
return type(self)(self.value + other)
284284

285-
def __eq__(self, other):
285+
def __eq__(self, other) -> bool:
286286
return type(other) is Thing and self.value == other.value
287287

288288
def __repr__(self) -> str:

pandas/tests/test_algos.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ def test_same_object_is_in(self):
767767
# with similar behavior, then we at least should
768768
# fall back to usual python's behavior: "a in [a] == True"
769769
class LikeNan:
770-
def __eq__(self, other):
770+
def __eq__(self, other) -> bool:
771771
return False
772772

773773
def __hash__(self):

pandas/tseries/offsets.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2577,7 +2577,7 @@ def __add__(self, other):
25772577
"will overflow".format(self=self, other=other)
25782578
)
25792579

2580-
def __eq__(self, other):
2580+
def __eq__(self, other) -> bool:
25812581
if isinstance(other, str):
25822582
from pandas.tseries.frequencies import to_offset
25832583

0 commit comments

Comments
 (0)