# xarray.CFTimeIndex.asof_locs

#### CFTimeIndex.asof_locs(where, mask)[[source]](https://github.com/pydata/xarray/blob/main/xarray/../.pixi/envs/doc/lib/python3.14/site-packages/pandas/core/indexes/base.py#L5805-L5870)

Return the locations (indices) of labels in the index.

As in the [`pandas.Index.asof()`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Index.asof.html#pandas.Index.asof), if the label (a particular entry in
`where`) is not in the index, the latest index label up to the
passed label is chosen and its index returned.

If all of the labels in the index are later than a label in `where`,
-1 is returned.

`mask` is used to ignore `NA` values in the index during calculation.

* **Parameters:**
  * **where** ([`Index`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Index.html#pandas.Index)) – An Index consisting of an array of timestamps.
  * **mask** (`np.ndarray[bool]`) – Array of booleans denoting where values in the original
    data are not `NA`.
* **Returns:**
  `np.ndarray[np.intp]` – An array of locations (indices) of the labels from the index
  which correspond to the return values of [`pandas.Index.asof()`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Index.asof.html#pandas.Index.asof)
  for every element in `where`.

#### SEE ALSO
`Index.asof`
: Return the label from the index, or, if not present, the previous one.

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('2951da2b-38c8-4564-9342-f1cfd7eb6831','8144f1e9-318b-4d8d-beb8-d2ccb2e67291','95b78b9a-881f-47b6-b0fe-c5f86bfbf41f','../lite/tree/../notebooks/index.html?path=3c5870f2_c475_4019_b382_0a6db8204e28.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> idx = pd.date_range("2023-06-01", periods=3, freq="D")
>>> where = pd.DatetimeIndex(
...     ["2023-05-30 00:12:00", "2023-06-01 00:00:00", "2023-06-02 23:59:59"]
... )
>>> mask = np.ones(3, dtype=bool)
>>> idx.asof_locs(where, mask)
array([-1,  0,  1])
```

We can use `mask` to ignore certain values in the index during calculation.

```pycon
>>> mask[1] = False
>>> idx.asof_locs(where, mask)
array([-1,  0,  0])
```

<div id="95b78b9a-881f-47b6-b0fe-c5f86bfbf41f" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('2951da2b-38c8-4564-9342-f1cfd7eb6831','95b78b9a-881f-47b6-b0fe-c5f86bfbf41f')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('2951da2b-38c8-4564-9342-f1cfd7eb6831','95b78b9a-881f-47b6-b0fe-c5f86bfbf41f')">Open In Tab</button></div><div id="8144f1e9-318b-4d8d-beb8-d2ccb2e67291" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
