# xarray.CFTimeIndex.slice_locs

#### CFTimeIndex.slice_locs(start=None, end=None, step=None)[[source]](https://github.com/pydata/xarray/blob/main/xarray/../.pixi/envs/doc/lib/python3.15/site-packages/pandas/core/indexes/base.py#L7335-L7450)

Compute slice locations for input labels.

This method determines the integer start and end positions for a
label-based slice, which is useful for translating label-based
slicing into positional slicing on the underlying data.

* **Parameters:**
  * **start** (`label`, *default* [`None`](https://docs.python.org/3/builtins/constants.html#None)) – If None, defaults to the beginning.
  * **end** (`label`, *default* [`None`](https://docs.python.org/3/builtins/constants.html#None)) – If None, defaults to the end.
  * **step** ([`int`](https://docs.python.org/3/builtins/functions.html#int), `defaults None`) – If None, defaults to 1.
* **Returns:**
  `tuple[int`, `int]` – Returns a tuple of two integers representing the slice locations for the
  input labels within the index.

#### SEE ALSO
`Index.get_loc`
: Get location for a single label.

`Index.get_slice_bound`
: Calculate the slice bound for a single label; used internally by `slice_locs` for each of `start` and `end`.

### Notes

This method only works if the index is monotonic or unique.

If `start` or `end` is not present in a monotonic index, the
returned position is the insertion point that preserves ordering
(analogous to [`numpy.searchsorted()`](https://numpy.org/doc/stable/reference/generated/numpy.searchsorted.html#numpy.searchsorted)); no error is raised. If the
index is not monotonic and the label is missing, a `KeyError` is
raised.

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('7a6355a3-9436-4c47-8a16-3a69c83c2696','243ae0b0-6fa6-4af6-8732-1611fc8d3072','0a3f30ad-e1fe-4e89-8c1f-119ad9a3404d','../lite/tree/../notebooks/index.html?path=dbe1fc89_3271_4bd0_9c93_09db98b1d9e5.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> idx = pd.Index(list("abcd"))
>>> idx.slice_locs(start="b", end="c")
(1, 3)
```

`start` and `end` need not be present in the index; for a
monotonic index they are mapped to the appropriate insertion
positions:

```pycon
>>> idx = pd.Index(list("bcde"))
>>> idx.slice_locs(start="a", end="c")
(0, 2)
```

<div id="0a3f30ad-e1fe-4e89-8c1f-119ad9a3404d" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('7a6355a3-9436-4c47-8a16-3a69c83c2696','0a3f30ad-e1fe-4e89-8c1f-119ad9a3404d')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('7a6355a3-9436-4c47-8a16-3a69c83c2696','0a3f30ad-e1fe-4e89-8c1f-119ad9a3404d')">Open In Tab</button></div><div id="243ae0b0-6fa6-4af6-8732-1611fc8d3072" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
