diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 68a0a4a403c81..327d1067dd17d 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -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 diff --git a/pandas/core/arrays/sparse/dtype.py b/pandas/core/arrays/sparse/dtype.py index 4de958cc386b9..3b656705f5568 100644 --- a/pandas/core/arrays/sparse/dtype.py +++ b/pandas/core/arrays/sparse/dtype.py @@ -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): diff --git a/pandas/core/dtypes/dtypes.py b/pandas/core/dtypes/dtypes.py index 523c8e8bd02d0..2c601b01dbae5 100644 --- a/pandas/core/dtypes/dtypes.py +++ b/pandas/core/dtypes/dtypes.py @@ -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 @@ -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() @@ -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): diff --git a/pandas/core/indexes/frozen.py b/pandas/core/indexes/frozen.py index 2c9521d23f71a..13c386187a9e5 100644 --- a/pandas/core/indexes/frozen.py +++ b/pandas/core/indexes/frozen.py @@ -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) diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index 18ae081caf69d..35205aa7dc267 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -2092,7 +2092,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) diff --git a/pandas/io/stata.py b/pandas/io/stata.py index 567eeb7f5cdc8..bd5e215730397 100644 --- a/pandas/io/stata.py +++ b/pandas/io/stata.py @@ -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 diff --git a/pandas/tests/indexing/test_indexing.py b/pandas/tests/indexing/test_indexing.py index ea9bc91a13111..09a66efb6a312 100644 --- a/pandas/tests/indexing/test_indexing.py +++ b/pandas/tests/indexing/test_indexing.py @@ -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): diff --git a/pandas/tests/scalar/timestamp/test_comparisons.py b/pandas/tests/scalar/timestamp/test_comparisons.py index 4ff0f84327854..fce4fa6eb1eaa 100644 --- a/pandas/tests/scalar/timestamp/test_comparisons.py +++ b/pandas/tests/scalar/timestamp/test_comparisons.py @@ -179,8 +179,8 @@ def __gt__(self, o): def __ge__(self, o): return True - def __eq__(self, o): - return isinstance(o, Inf) + def __eq__(self, other) -> bool: + return isinstance(other, Inf) inf = Inf() timestamp = Timestamp("2018-11-30") diff --git a/pandas/tests/series/test_ufunc.py b/pandas/tests/series/test_ufunc.py index c8a127f89bf91..977e7ded1f1a7 100644 --- a/pandas/tests/series/test_ufunc.py +++ b/pandas/tests/series/test_ufunc.py @@ -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: diff --git a/pandas/tests/test_algos.py b/pandas/tests/test_algos.py index 9e89a1b6f0467..02b50d84c6eca 100644 --- a/pandas/tests/test_algos.py +++ b/pandas/tests/test_algos.py @@ -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): diff --git a/pandas/tseries/offsets.py b/pandas/tseries/offsets.py index e516d30d5490f..0620f2b9aae49 100644 --- a/pandas/tseries/offsets.py +++ b/pandas/tseries/offsets.py @@ -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