Skip to content

REF: dont catch TypeError in Loc #42729

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

Merged
merged 1 commit into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2836,7 +2836,7 @@ def _maybe_to_slice(loc):
try:
return self._engine.get_loc(key)
except TypeError:
# e.g. partial string slicing
# e.g. test_partial_slicing_with_multiindex partial string slicing
loc, _ = self.get_loc_level(key, list(range(self.nlevels)))
return loc

Expand Down
15 changes: 2 additions & 13 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,16 +658,7 @@ def _get_setitem_indexer(self, key):
if isinstance(key, range):
return list(key)

try:
return self._convert_to_indexer(key, axis=0, is_setter=True)
except TypeError as e:

# invalid indexer type vs 'other' indexing errors
if "cannot do" in str(e):
raise
elif "unhashable type" in str(e):
raise
raise IndexingError(key) from e
return self._convert_to_indexer(key, axis=0, is_setter=True)

def _ensure_listlike_indexer(self, key, axis=None, value=None):
"""
Expand Down Expand Up @@ -1209,7 +1200,7 @@ def _convert_to_indexer(self, key, axis: int, is_setter: bool = False):
is_int_index = labels.is_integer()
is_int_positional = is_integer(key) and not is_int_index

if is_scalar(key) or isinstance(labels, MultiIndex):
if is_scalar(key) or (isinstance(labels, MultiIndex) and is_hashable(key)):
# Otherwise get_loc will raise InvalidIndexError

# if we are a label return me
Expand All @@ -1224,8 +1215,6 @@ def _convert_to_indexer(self, key, axis: int, is_setter: bool = False):
# GH35015, using datetime as column indices raises exception
if not isinstance(labels, MultiIndex):
raise
except TypeError:
pass
except ValueError:
if not is_int_positional:
raise
Expand Down