-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
BUG: raise on non-hashable in __contains__ #30902
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
30c43b6
d38cc26
d74f501
7dc6c22
faec826
d960dd3
ee0093f
0a9884d
c1005d4
5b8d39c
dd4508f
dfa975d
0a3a417
8d53b27
892c9c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,9 +72,10 @@ cdef class IndexEngine: | |
self.over_size_threshold = n >= _SIZE_CUTOFF | ||
self.clear_mapping() | ||
|
||
def __contains__(self, object val): | ||
def __contains__(self, val: object) -> bool: | ||
# We assume before we get here: | ||
# - val is hashable | ||
self._ensure_mapping_populated() | ||
hash(val) | ||
return val in self.mapping | ||
|
||
cpdef get_value(self, ndarray arr, object key, object tz=None): | ||
|
@@ -415,7 +416,9 @@ cdef class DatetimeEngine(Int64Engine): | |
raise TypeError(scalar) | ||
return scalar.value | ||
|
||
def __contains__(self, object val): | ||
def __contains__(self, val: object) -> bool: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
# We assume before we get here: | ||
# - val is hashable | ||
cdef: | ||
int64_t loc, conv | ||
|
||
|
@@ -712,7 +715,9 @@ cdef class BaseMultiIndexCodesEngine: | |
|
||
return indexer | ||
|
||
def __contains__(self, object val): | ||
def __contains__(self, val: object) -> bool: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
# We assume before we get here: | ||
# - val is hashable | ||
# Default __contains__ looks in the underlying mapping, which in this | ||
# case only contains integer representations. | ||
try: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -385,11 +385,12 @@ def _wrap_setop_result(self, other, result): | |
return self._shallow_copy(result, name=name) | ||
|
||
@Appender(_index_shared_docs["contains"] % _index_doc_kwargs) | ||
def __contains__(self, key) -> bool: | ||
def __contains__(self, key: Any) -> bool: | ||
# if key is a NaN, check if any NaN is in self. | ||
if is_scalar(key) and isna(key): | ||
return self.hasnans | ||
|
||
hash(key) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume this is to check that key is hashable. can you not type key as Hashable? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's not a run-time check |
||
return contains(self, key, container=self._engine) | ||
|
||
def __array__(self, dtype=None) -> np.ndarray: | ||
|
Uh oh!
There was an error while loading. Please reload this page.