MCPcopy
hub / github.com/pandas-dev/pandas / _getitem_slice

Method _getitem_slice

pandas/core/generic.py:4280–4294  ·  view source on GitHub ↗

__getitem__ for the case where the key is a slice object.

(self, key: slice)

Source from the content-addressed store, hash-verified

4278
4279 @final
4280 def _getitem_slice(self, key: slice) -> Self:
4281 """
4282 __getitem__ for the case where the key is a slice object.
4283 """
4284 # _convert_slice_indexer to determine if this slice is positional
4285 # or label based, and if the latter, convert to positional
4286 slobj = self.index._convert_slice_indexer(key, kind="getitem")
4287 if isinstance(slobj, np.ndarray):
4288 # reachable with DatetimeIndex
4289 indexer = lib.maybe_indices_to_slice(slobj.astype(np.intp), len(self))
4290 if isinstance(indexer, np.ndarray):
4291 # GH#43223 If we can not convert, use take
4292 return self.take(indexer, axis=0)
4293 slobj = indexer
4294 return self._slice(slobj)
4295
4296 def _slice(self, slobj: slice, axis: AxisInt = 0) -> Self:
4297 """

Callers 2

__getitem__Method · 0.45
__getitem__Method · 0.45

Calls 4

takeMethod · 0.95
_sliceMethod · 0.95
astypeMethod · 0.45

Tested by

no test coverage detected