Skip to content

Commit 7469276

Browse files
committed
simplify __contains__ by reusing getitem code
1 parent af8cb0b commit 7469276

File tree

1 file changed

+3
-15
lines changed

1 file changed

+3
-15
lines changed

pandas/src/hashtable_class_helper.pxi.in

+3-15
Original file line numberDiff line numberDiff line change
@@ -887,23 +887,11 @@ cdef class MultiIndexHashTable(HashTable):
887887
"result:\n{}\nmi:\n{}".format(alocs, result, mi))
888888

889889
def __contains__(self, object key):
890-
cdef:
891-
khiter_t k
892-
uint64_t value
893-
894890
try:
895-
value = self.mi._hashed_indexing_key(key)
896-
except TypeError:
897-
return False
898-
899-
k = kh_get_uint64(self.table, value)
900-
if k != self.table.n_buckets:
901-
loc = self.table.vals[k]
902-
locs = np.array([loc], dtype=np.int64)
903-
self._check_for_collisions(locs, key)
891+
self.get_item(key)
904892
return True
905-
906-
return False
893+
except (KeyError, ValueError, TypeError):
894+
return False
907895

908896
cpdef get_item(self, object key):
909897
cdef:

0 commit comments

Comments
 (0)