Skip to content

Commit e69277e

Browse files
author
MomIsBestFriend
committed
Added 'Any' type annotation to 'other' in __eq__
1 parent 489f757 commit e69277e

File tree

14 files changed

+30
-21
lines changed

14 files changed

+30
-21
lines changed

pandas/_libs/tslibs/offsets.pyx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import cython
22

33
import time
4+
from typing import Any
45
from cpython.datetime cimport (PyDateTime_IMPORT,
56
PyDateTime_Check,
67
PyDelta_Check,
@@ -328,7 +329,7 @@ class _BaseOffset:
328329
def __setattr__(self, name, value):
329330
raise AttributeError("DateOffset objects are immutable.")
330331

331-
def __eq__(self, other: object) -> bool:
332+
def __eq__(self, other: Any) -> bool:
332333
if isinstance(other, str):
333334
try:
334335
# GH#23524 if to_offset fails, we are dealing with an

pandas/core/arrays/sparse/dtype.py

Lines changed: 1 addition & 1 deletion
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: object) -> bool:
93+
def __eq__(self, other: Any) -> 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/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Extend pandas with custom array types"""
2-
from typing import List, Optional, Tuple, Type
2+
from typing import Any, List, Optional, Tuple, Type
33

44
import numpy as np
55

@@ -86,7 +86,7 @@ def __from_arrow__(
8686
def __str__(self) -> str:
8787
return self.name
8888

89-
def __eq__(self, other: object) -> bool:
89+
def __eq__(self, other: Any) -> bool:
9090
"""
9191
Check whether 'other' is equal to self.
9292

pandas/core/dtypes/dtypes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ def __hash__(self) -> int:
370370
# We *do* want to include the real self.ordered here
371371
return int(self._hash_categories(self.categories, self._ordered))
372372

373-
def __eq__(self, other: object) -> bool:
373+
def __eq__(self, other: Any) -> bool:
374374
"""
375375
Rules for CDT equality:
376376
1) Any CDT is equal to the string 'category'
@@ -765,7 +765,7 @@ def __hash__(self) -> int:
765765
# TODO: update this.
766766
return hash(str(self))
767767

768-
def __eq__(self, other: object) -> bool:
768+
def __eq__(self, other: Any) -> 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: object) -> bool:
907+
def __eq__(self, other: Any) -> 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: object) -> bool:
1080+
def __eq__(self, other: Any) -> 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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- .levels & .codes (FrozenNDArray)
88
99
"""
10+
from typing import Any
1011
import warnings
1112

1213
import numpy as np
@@ -77,7 +78,7 @@ def __radd__(self, other):
7778
other = list(other)
7879
return self.__class__(other + list(self))
7980

80-
def __eq__(self, other: object) -> bool:
81+
def __eq__(self, other: Any) -> bool:
8182
if isinstance(other, (tuple, FrozenList)):
8283
other = list(other)
8384
return super().__eq__(other)

pandas/io/pytables.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,7 +1773,7 @@ def __repr__(self) -> str:
17731773
)
17741774
)
17751775

1776-
def __eq__(self, other: object) -> bool:
1776+
def __eq__(self, other: Any) -> bool:
17771777
""" compare 2 col items """
17781778
return all(
17791779
getattr(self, a, None) == getattr(other, a, None)
@@ -2109,7 +2109,7 @@ def __repr__(self) -> str:
21092109
)
21102110
)
21112111

2112-
def __eq__(self, other: object) -> bool:
2112+
def __eq__(self, other: Any) -> bool:
21132113
""" compare 2 col items """
21142114
return all(
21152115
getattr(self, a, None) == getattr(other, a, None)

pandas/io/stata.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import os
1717
import struct
1818
import sys
19+
from typing import Any
1920
import warnings
2021

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

862-
def __eq__(self, other: object) -> bool:
863+
def __eq__(self, other: Any) -> bool:
863864
return (
864865
isinstance(other, self.__class__)
865866
and self.string == other.string

pandas/tests/groupby/test_function.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from io import StringIO
44
from itertools import product
55
from string import ascii_lowercase
6+
from typing import Any
67

78
import numpy as np
89
import pytest
@@ -1230,7 +1231,7 @@ def __init__(self, msg="I will raise inside Cython"):
12301231
super().__init__()
12311232
self.msg = msg
12321233

1233-
def __eq__(self, other: object):
1234+
def __eq__(self, other: Any):
12341235
# gets called in Cython to check that raising calls the method
12351236
raise RaisingObjectException(self.msg)
12361237

pandas/tests/indexing/test_indexing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from datetime import datetime
44
import re
5+
from typing import Any
56
import weakref
67

78
import numpy as np
@@ -595,7 +596,7 @@ def __str__(self) -> str:
595596

596597
__repr__ = __str__
597598

598-
def __eq__(self, other: object) -> bool:
599+
def __eq__(self, other: Any) -> bool:
599600
return self.value == other.value
600601

601602
def view(self):

pandas/tests/scalar/timedelta/test_timedelta.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
""" test the scalar Timedelta """
22
from datetime import timedelta
33
import re
4+
from typing import Any
45

56
import numpy as np
67
import pytest
@@ -139,7 +140,7 @@ def generic_result(self):
139140
else:
140141
return self.cmp_result
141142

142-
def __eq__(self, other: object):
143+
def __eq__(self, other: Any):
143144
return self.generic_result()
144145

145146
def __gt__(self, other):

pandas/tests/scalar/timestamp/test_comparisons.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from datetime import datetime
22
import operator
3+
from typing import Any
34

45
import numpy as np
56
import pytest
@@ -179,8 +180,8 @@ def __gt__(self, o):
179180
def __ge__(self, o):
180181
return True
181182

182-
def __eq__(self, o: object) -> bool:
183-
return isinstance(o, Inf)
183+
def __eq__(self, other: Any) -> bool:
184+
return isinstance(other, Inf)
184185

185186
inf = Inf()
186187
timestamp = Timestamp("2018-11-30")

pandas/tests/series/test_ufunc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from collections import deque
22
import string
3+
from typing import Any
34

45
import numpy as np
56
import pytest
@@ -282,7 +283,7 @@ def __add__(self, other):
282283
other = getattr(other, "value", other)
283284
return type(self)(self.value + other)
284285

285-
def __eq__(self, other: object) -> bool:
286+
def __eq__(self, other: Any) -> bool:
286287
return type(other) is Thing and self.value == other.value
287288

288289
def __repr__(self) -> str:

pandas/tests/test_algos.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from datetime import datetime
22
from itertools import permutations
33
import struct
4+
from typing import Any
45

56
import numpy as np
67
from numpy.random import RandomState
@@ -767,7 +768,7 @@ def test_same_object_is_in(self):
767768
# with similar behavior, then we at least should
768769
# fall back to usual python's behavior: "a in [a] == True"
769770
class LikeNan:
770-
def __eq__(self, other: object) -> bool:
771+
def __eq__(self, other: Any) -> bool:
771772
return False
772773

773774
def __hash__(self):

pandas/tseries/offsets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from datetime import date, datetime, timedelta
22
import functools
33
import operator
4-
from typing import Optional
4+
from typing import Any, Optional
55

66
from dateutil.easter import easter
77
import numpy as np
@@ -2577,7 +2577,7 @@ def __add__(self, other):
25772577
"will overflow".format(self=self, other=other)
25782578
)
25792579

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

0 commit comments

Comments
 (0)