Skip to content

Commit

Permalink
Annotations to __eq__ function
Browse files Browse the repository at this point in the history
  • Loading branch information
MomIsBestFriend committed Nov 27, 2019
1 parent 68115de commit 0bf439b
Show file tree
Hide file tree
Showing 14 changed files with 19 additions and 28 deletions.
3 changes: 1 addition & 2 deletions pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import cython

import time
from typing import Any
from cpython.datetime cimport (PyDateTime_IMPORT,
PyDateTime_Check,
PyDelta_Check,
Expand Down Expand Up @@ -329,7 +328,7 @@ class _BaseOffset:
def __setattr__(self, name, value):
raise AttributeError("DateOffset objects are immutable.")

def __eq__(self, other: Any) -> bool:
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: Any) -> bool:
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
4 changes: 2 additions & 2 deletions pandas/core/dtypes/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Extend pandas with custom array types"""
from typing import Any, List, Optional, Tuple, Type
from typing import List, Optional, Tuple, Type

import numpy as np

Expand Down Expand Up @@ -86,7 +86,7 @@ def __from_arrow__(
def __str__(self) -> str:
return self.name

def __eq__(self, other: Any) -> bool:
def __eq__(self, other) -> bool:
"""
Check whether 'other' is equal to self.
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: Any) -> bool:
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: Any) -> bool:
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: Any) -> bool:
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
3 changes: 1 addition & 2 deletions pandas/core/indexes/frozen.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
- .levels & .codes (FrozenNDArray)
"""
from typing import Any
import warnings

import numpy as np
Expand Down Expand Up @@ -78,7 +77,7 @@ def __radd__(self, other):
other = list(other)
return self.__class__(other + list(self))

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

def __eq__(self, other: Any) -> bool:
def __eq__(self, other) -> bool:
""" compare 2 col items """
return all(
getattr(self, a, None) == getattr(other, a, None)
Expand Down Expand Up @@ -2092,7 +2092,7 @@ def __repr__(self) -> str:
)
)

def __eq__(self, other: Any) -> bool:
def __eq__(self, other) -> bool:
""" compare 2 col items """
return all(
getattr(self, a, None) == getattr(other, a, None)
Expand Down
3 changes: 1 addition & 2 deletions pandas/io/stata.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import os
import struct
import sys
from typing import Any
import warnings

from dateutil.relativedelta import relativedelta
Expand Down Expand Up @@ -860,7 +859,7 @@ def __repr__(self) -> str:
# not perfect :-/
return "{cls}({obj})".format(cls=self.__class__, obj=self)

def __eq__(self, other: Any) -> bool:
def __eq__(self, other) -> bool:
return (
isinstance(other, self.__class__)
and self.string == other.string
Expand Down
3 changes: 1 addition & 2 deletions pandas/tests/groupby/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from io import StringIO
from itertools import product
from string import ascii_lowercase
from typing import Any

import numpy as np
import pytest
Expand Down Expand Up @@ -1231,7 +1230,7 @@ def __init__(self, msg="I will raise inside Cython"):
super().__init__()
self.msg = msg

def __eq__(self, other: Any):
def __eq__(self, other):
# gets called in Cython to check that raising calls the method
raise RaisingObjectException(self.msg)

Expand Down
3 changes: 1 addition & 2 deletions pandas/tests/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from datetime import datetime
import re
from typing import Any
import weakref

import numpy as np
Expand Down Expand Up @@ -596,7 +595,7 @@ def __str__(self) -> str:

__repr__ = __str__

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

def view(self):
Expand Down
3 changes: 1 addition & 2 deletions pandas/tests/scalar/timedelta/test_timedelta.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
""" test the scalar Timedelta """
from datetime import timedelta
import re
from typing import Any

import numpy as np
import pytest
Expand Down Expand Up @@ -134,7 +133,7 @@ def generic_result(self):
else:
return self.cmp_result

def __eq__(self, other: Any):
def __eq__(self, other):
return self.generic_result()

def __gt__(self, other):
Expand Down
3 changes: 1 addition & 2 deletions pandas/tests/scalar/timestamp/test_comparisons.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from datetime import datetime
import operator
from typing import Any

import numpy as np
import pytest
Expand Down Expand Up @@ -180,7 +179,7 @@ def __gt__(self, o):
def __ge__(self, o):
return True

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

inf = Inf()
Expand Down
3 changes: 1 addition & 2 deletions pandas/tests/series/test_ufunc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from collections import deque
import string
from typing import Any

import numpy as np
import pytest
Expand Down Expand Up @@ -283,7 +282,7 @@ def __add__(self, other):
other = getattr(other, "value", other)
return type(self)(self.value + other)

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

def __repr__(self) -> str:
Expand Down
3 changes: 1 addition & 2 deletions pandas/tests/test_algos.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from datetime import datetime
from itertools import permutations
import struct
from typing import Any

import numpy as np
from numpy.random import RandomState
Expand Down Expand Up @@ -768,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: Any) -> bool:
def __eq__(self, other) -> bool:
return False

def __hash__(self):
Expand Down
4 changes: 2 additions & 2 deletions pandas/tseries/offsets.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from datetime import date, datetime, timedelta
import functools
import operator
from typing import Any, Optional
from typing import Optional

from dateutil.easter import easter
import numpy as np
Expand Down Expand Up @@ -2577,7 +2577,7 @@ def __add__(self, other):
"will overflow".format(self=self, other=other)
)

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

Expand Down

0 comments on commit 0bf439b

Please sign in to comment.