REF: write indexing checks in terms of should_fallback_to_positional … · pandas-dev/pandas@98ca9f0 (original) (raw)

3 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -4205,9 +4205,14 @@ def is_int(v):
4205 4205 return v is None or is_integer(v)
4206 4206
4207 4207 is_index_slice = is_int(start) and is_int(stop) and is_int(step)
4208 -is_positional = is_index_slice and not (
4209 -self.is_integer() or self.is_categorical()
4208 +
4209 +# special case for interval_dtype bc we do not do partial-indexing
4210 +# on integer Intervals when slicing
4211 +# TODO: write this in terms of e.g. should_partial_index?
4212 +ints_are_positional = self._should_fallback_to_positional or is_interval_dtype(
4213 +self.dtype
4210 4214 )
4215 +is_positional = is_index_slice and ints_are_positional
4211 4216
4212 4217 if kind == "getitem":
4213 4218 """
Original file line number Diff line number Diff line change
@@ -222,6 +222,8 @@ def _convert_slice_indexer(self, key: slice, kind: str, is_frame: bool = False):
222 222 if is_float_dtype(self.dtype):
223 223 assert kind in ["loc", "getitem"]
224 224
225 +# TODO: can we write this as a condition based on
226 +# e.g. _should_fallback_to_positional?
225 227 # We always treat __getitem__ slicing as label-based
226 228 # translate to locations
227 229 return self.slice_indexer(key.start, key.stop, key.step)
Original file line number Diff line number Diff line change
@@ -1322,10 +1322,6 @@ def _convert_to_indexer(self, key, axis: int):
1322 1322 if isinstance(key, slice):
1323 1323 return labels._convert_slice_indexer(key, kind="loc")
1324 1324
1325 -# see if we are positional in nature
1326 -is_int_index = labels.is_integer()
1327 -is_int_positional = is_integer(key) and not is_int_index
1328 -
1329 1325 if (
1330 1326 isinstance(key, tuple)
1331 1327 and not isinstance(labels, MultiIndex)
@@ -1350,17 +1346,9 @@ def _convert_to_indexer(self, key, axis: int):
1350 1346 if not isinstance(labels, MultiIndex):
1351 1347 raise
1352 1348 except ValueError:
1353 -if not is_int_positional:
1349 +if not is_integer(key):
1354 1350 raise
1355 -
1356 -# a positional
1357 -if is_int_positional:
1358 -
1359 -# if we are setting and its not a valid location
1360 -# its an insert which fails by definition
1361 -
1362 -# always valid
1363 -return {"key": key}
1351 +return {"key": key}
1364 1352
1365 1353 if is_nested_tuple(key, labels):
1366 1354 if self.ndim == 1 and any(isinstance(k, tuple) for k in key):