-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Make MultiIndex.get_loc raise for unhashable type #35914
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 1 commit
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 |
---|---|---|
|
@@ -2707,6 +2707,8 @@ def get_loc(self, key, method=None): | |
"currently supported for MultiIndex" | ||
) | ||
|
||
hash(key) | ||
|
||
def _maybe_to_slice(loc): | ||
"""convert integer indexer to boolean mask or slice if possible""" | ||
if not isinstance(loc, np.ndarray) or loc.dtype != "int64": | ||
|
@@ -2721,8 +2723,7 @@ def _maybe_to_slice(loc): | |
mask[loc] = True | ||
return mask | ||
|
||
if not isinstance(key, (tuple, list)): | ||
# not including list here breaks some indexing, xref #30892 | ||
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 think it is okay to remove this comment since we're not actually checking for list here, or should it be moved? cc @jbrockmendel 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 think youre right (though havent checked 30892) |
||
if not isinstance(key, tuple): | ||
loc = self._get_level_indexer(key, level=0) | ||
return _maybe_to_slice(loc) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this raise InvalidIndexError?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was my original thought, but it broke an existing test because evidently passing a singleton list with only np.nan raises the unhashable type error (it hits a line that uses this approach of trying to hash the key):