Skip to content

Commit ddd7550

Browse files
jbrockmendelCGe0516
authored andcommitted
REF: dont catch TypeError in Loc (pandas-dev#42729)
1 parent ab3d70c commit ddd7550

File tree

2 files changed

+3
-14
lines changed

2 files changed

+3
-14
lines changed

pandas/core/indexes/multi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2836,7 +2836,7 @@ def _maybe_to_slice(loc):
28362836
try:
28372837
return self._engine.get_loc(key)
28382838
except TypeError:
2839-
# e.g. partial string slicing
2839+
# e.g. test_partial_slicing_with_multiindex partial string slicing
28402840
loc, _ = self.get_loc_level(key, list(range(self.nlevels)))
28412841
return loc
28422842

pandas/core/indexing.py

+2-13
Original file line numberDiff line numberDiff line change
@@ -658,16 +658,7 @@ def _get_setitem_indexer(self, key):
658658
if isinstance(key, range):
659659
return list(key)
660660

661-
try:
662-
return self._convert_to_indexer(key, axis=0, is_setter=True)
663-
except TypeError as e:
664-
665-
# invalid indexer type vs 'other' indexing errors
666-
if "cannot do" in str(e):
667-
raise
668-
elif "unhashable type" in str(e):
669-
raise
670-
raise IndexingError(key) from e
661+
return self._convert_to_indexer(key, axis=0, is_setter=True)
671662

672663
def _ensure_listlike_indexer(self, key, axis=None, value=None):
673664
"""
@@ -1209,7 +1200,7 @@ def _convert_to_indexer(self, key, axis: int, is_setter: bool = False):
12091200
is_int_index = labels.is_integer()
12101201
is_int_positional = is_integer(key) and not is_int_index
12111202

1212-
if is_scalar(key) or isinstance(labels, MultiIndex):
1203+
if is_scalar(key) or (isinstance(labels, MultiIndex) and is_hashable(key)):
12131204
# Otherwise get_loc will raise InvalidIndexError
12141205

12151206
# if we are a label return me
@@ -1224,8 +1215,6 @@ def _convert_to_indexer(self, key, axis: int, is_setter: bool = False):
12241215
# GH35015, using datetime as column indices raises exception
12251216
if not isinstance(labels, MultiIndex):
12261217
raise
1227-
except TypeError:
1228-
pass
12291218
except ValueError:
12301219
if not is_int_positional:
12311220
raise

0 commit comments

Comments
 (0)