Skip to content

Commit 915d0a3

Browse files
DOC: convert how-to-create-custom-index.rst code blocks (#11255)
Co-authored-by: Claude <noreply@anthropic.com>
1 parent 3a1fb6a commit 915d0a3

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

doc/internals/how-to-create-custom-index.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ Here is a small example of a meta-index for geospatial, raster datasets (i.e.,
154154
regularly spaced 2-dimensional data) that internally relies on two
155155
``PandasIndex`` instances for the x and y dimensions respectively:
156156

157-
.. code-block:: python
157+
.. jupyter-execute::
158158

159159
from xarray import Index
160160
from xarray.core.indexes import PandasIndex
@@ -172,11 +172,12 @@ regularly spaced 2-dimensional data) that internally relies on two
172172
self._xy_indexes = xy_indexes
173173

174174
@classmethod
175-
def from_variables(cls, variables):
175+
def from_variables(cls, variables, *, options):
176176
assert len(variables) == 2
177177
178178
xy_indexes = {
179-
k: PandasIndex.from_variables({k: v}) for k, v in variables.items()
179+
k: PandasIndex.from_variables({k: v}, options=options)
180+
for k, v in variables.items()
180181
}
181182

182183
return cls(xy_indexes)
@@ -213,7 +214,7 @@ How to use a custom index
213214
You can use :py:meth:`Dataset.set_xindex` or :py:meth:`DataArray.set_xindex` to assign a
214215
custom index to a Dataset or DataArray, e.g., using the ``RasterIndex`` above:
215216

216-
.. code-block:: python
217+
.. jupyter-execute::
217218

218219
import numpy as np
219220
import xarray as xr
@@ -231,3 +232,4 @@ custom index to a Dataset or DataArray, e.g., using the ``RasterIndex`` above:
231232

232233
# RasterIndex now takes care of label-based selection
233234
selected = da_raster.sel(x=10, y=slice(20, 50))
235+
selected

doc/whats-new.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ Documentation
119119

120120
- Fix typos (:pull:`11180`, :pull:`11181`, :pull:`11182`, :pull:`11185`, :pull:`11186`).
121121
By `Yaocheng Chen <https://github.com/yaochengchen>`_.
122+
- Fix code blocks on "how to create custom index" doc page (:pull:`11255`).
123+
By `Nick Hodgskin <https://github.com/VeckoTheGecko>`_.
122124

123125
Internal Changes
124126
~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)