Skip to content

Commit 152de93

Browse files
committed
annotate __contains__
1 parent ad8d13e commit 152de93

File tree

5 files changed

+12
-9
lines changed

5 files changed

+12
-9
lines changed

pandas/core/indexes/category.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, List
1+
from typing import Any, Hashable, List, Optional
22
import warnings
33

44
import numpy as np
@@ -385,7 +385,7 @@ def _wrap_setop_result(self, other, result):
385385
return self._shallow_copy(result, name=name)
386386

387387
@Appender(_index_shared_docs["contains"] % _index_doc_kwargs)
388-
def __contains__(self, key) -> bool:
388+
def __contains__(self, key: Optional[Hashable]) -> bool:
389389
# if key is a NaN, check if any NaN is in self.
390390
if is_scalar(key) and isna(key):
391391
return self.hasnans

pandas/core/indexes/datetimelike.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Base and utility classes for tseries type pandas objects.
33
"""
44
import operator
5-
from typing import List, Optional, Set
5+
from typing import Hashable, List, Optional, Set
66

77
import numpy as np
88

@@ -153,7 +153,7 @@ def equals(self, other) -> bool:
153153
return np.array_equal(self.asi8, other.asi8)
154154

155155
@Appender(_index_shared_docs["contains"] % _index_doc_kwargs)
156-
def __contains__(self, key):
156+
def __contains__(self, key: Optional[Hashable]):
157157
hash(key)
158158
try:
159159
res = self.get_loc(key)

pandas/core/indexes/interval.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
""" define the IntervalIndex """
22
from operator import le, lt
33
import textwrap
4-
from typing import Any, Optional, Tuple, Union
4+
from typing import Any, Hashable, Optional, Tuple, Union
55

66
import numpy as np
77

@@ -372,7 +372,7 @@ def _engine(self):
372372
right = self._maybe_convert_i8(self.right)
373373
return IntervalTree(left, right, closed=self.closed)
374374

375-
def __contains__(self, key) -> bool:
375+
def __contains__(self, key: Optional[Hashable]) -> bool:
376376
"""
377377
return a boolean if this key is IN the index
378378
We *only* accept an Interval

pandas/core/indexes/numeric.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Hashable, Optional
2+
13
import numpy as np
24

35
from pandas._libs import index as libindex, lib
@@ -225,7 +227,7 @@ class IntegerIndex(NumericIndex):
225227
This is an abstract class for Int64Index, UInt64Index.
226228
"""
227229

228-
def __contains__(self, key) -> bool:
230+
def __contains__(self, key: Optional[Hashable]) -> bool:
229231
"""
230232
Check if key is a float and has a decimal. If it has, return False.
231233
"""
@@ -473,7 +475,7 @@ def equals(self, other) -> bool:
473475
except (TypeError, ValueError):
474476
return False
475477

476-
def __contains__(self, other) -> bool:
478+
def __contains__(self, other: Optional[Hashable]) -> bool:
477479
hash(other)
478480
if super().__contains__(other):
479481
return True

pandas/core/indexes/period.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from datetime import datetime, timedelta
2+
from typing import Hashable, Optional
23
import weakref
34

45
import numpy as np
@@ -370,7 +371,7 @@ def _engine(self):
370371
return self._engine_type(period, len(self))
371372

372373
@Appender(_index_shared_docs["contains"])
373-
def __contains__(self, key) -> bool:
374+
def __contains__(self, key: Optional[Hashable]) -> bool:
374375
if isinstance(key, Period):
375376
if key.freq != self.freq:
376377
return False

0 commit comments

Comments
 (0)