Skip to content

Commit

Permalink
Added annotation to __eq__
Browse files Browse the repository at this point in the history
  • Loading branch information
MomIsBestFriend committed Nov 23, 2019
1 parent d55258f commit 4b9cc76
Show file tree
Hide file tree
Showing 11 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ class _BaseOffset:
def __setattr__(self, name, value):
raise AttributeError("DateOffset objects are immutable.")

def __eq__(self, other):
def __eq__(self, other) -> bool:
if isinstance(other, str):
try:
# GH#23524 if to_offset fails, we are dealing with an
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 @@ -90,7 +90,7 @@ def __hash__(self):
# __eq__, so we explicitly do it here.
return super().__hash__()

def __eq__(self, other):
def __eq__(self, other) -> bool:
# We have to override __eq__ to handle NA values in _metadata.
# The base class does simple == checks, which fail for NA.
if isinstance(other, str):
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ def __hash__(self) -> int:
# TODO: update this.
return hash(str(self))

def __eq__(self, other):
def __eq__(self, other) -> bool:
if isinstance(other, str):
return other == self.name

Expand Down Expand Up @@ -904,7 +904,7 @@ def __hash__(self) -> int:
# make myself hashable
return hash(str(self))

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

Expand Down Expand Up @@ -1077,7 +1077,7 @@ def __hash__(self) -> int:
# make myself hashable
return hash(str(self))

def __eq__(self, other):
def __eq__(self, other) -> bool:
if isinstance(other, str):
return other.lower() in (self.name.lower(), str(self).lower())
elif not isinstance(other, IntervalDtype):
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/frozen.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __radd__(self, other):
other = list(other)
return self.__class__(other + list(self))

def __eq__(self, other):
def __eq__(self, other) -> bool:
if isinstance(other, (tuple, FrozenList)):
other = list(other)
return super().__eq__(other)
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -2109,7 +2109,7 @@ def __repr__(self) -> str:
)
)

def __eq__(self, other):
def __eq__(self, other) -> bool:
""" compare 2 col items """
return all(
getattr(self, a, None) == getattr(other, a, None)
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/stata.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ def __repr__(self) -> str:
# not perfect :-/
return "{cls}({obj})".format(cls=self.__class__, obj=self)

def __eq__(self, other):
def __eq__(self, other) -> bool:
return (
isinstance(other, self.__class__)
and self.string == other.string
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ def __str__(self) -> str:

__repr__ = __str__

def __eq__(self, other):
def __eq__(self, other) -> bool:
return self.value == other.value

def view(self):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/scalar/timestamp/test_comparisons.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def __gt__(self, o):
def __ge__(self, o):
return True

def __eq__(self, o):
def __eq__(self, o) -> bool:
return isinstance(o, Inf)

inf = Inf()
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/test_ufunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def __add__(self, other):
other = getattr(other, "value", other)
return type(self)(self.value + other)

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

def __repr__(self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/test_algos.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ def test_same_object_is_in(self):
# with similar behavior, then we at least should
# fall back to usual python's behavior: "a in [a] == True"
class LikeNan:
def __eq__(self, other):
def __eq__(self, other) -> bool:
return False

def __hash__(self):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tseries/offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2577,7 +2577,7 @@ def __add__(self, other):
"will overflow".format(self=self, other=other)
)

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

Expand Down

0 comments on commit 4b9cc76

Please sign in to comment.