From 915d0a359136e0287cd85b3a025cdefe9762471b Mon Sep 17 00:00:00 2001 From: Nick Hodgskin <36369090+VeckoTheGecko@users.noreply.github.com> Date: Tue, 24 Mar 2026 09:56:29 +0100 Subject: [PATCH] DOC: convert how-to-create-custom-index.rst code blocks (#11255) Co-authored-by: Claude --- doc/internals/how-to-create-custom-index.rst | 10 ++++++---- doc/whats-new.rst | 2 ++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/doc/internals/how-to-create-custom-index.rst b/doc/internals/how-to-create-custom-index.rst index 2002915ac84..d7e912aa7bf 100644 --- a/doc/internals/how-to-create-custom-index.rst +++ b/doc/internals/how-to-create-custom-index.rst @@ -154,7 +154,7 @@ Here is a small example of a meta-index for geospatial, raster datasets (i.e., regularly spaced 2-dimensional data) that internally relies on two ``PandasIndex`` instances for the x and y dimensions respectively: -.. code-block:: python +.. jupyter-execute:: from xarray import Index from xarray.core.indexes import PandasIndex @@ -172,11 +172,12 @@ regularly spaced 2-dimensional data) that internally relies on two self._xy_indexes = xy_indexes @classmethod - def from_variables(cls, variables): + def from_variables(cls, variables, *, options): assert len(variables) == 2 xy_indexes = { - k: PandasIndex.from_variables({k: v}) for k, v in variables.items() + k: PandasIndex.from_variables({k: v}, options=options) + for k, v in variables.items() } return cls(xy_indexes) @@ -213,7 +214,7 @@ How to use a custom index You can use :py:meth:`Dataset.set_xindex` or :py:meth:`DataArray.set_xindex` to assign a custom index to a Dataset or DataArray, e.g., using the ``RasterIndex`` above: -.. code-block:: python +.. jupyter-execute:: import numpy as np import xarray as xr @@ -231,3 +232,4 @@ custom index to a Dataset or DataArray, e.g., using the ``RasterIndex`` above: # RasterIndex now takes care of label-based selection selected = da_raster.sel(x=10, y=slice(20, 50)) + selected diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 35db6ba93e6..f714e3f7b07 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -119,6 +119,8 @@ Documentation - Fix typos (:pull:`11180`, :pull:`11181`, :pull:`11182`, :pull:`11185`, :pull:`11186`). By `Yaocheng Chen `_. +- Fix code blocks on "how to create custom index" doc page (:pull:`11255`). + By `Nick Hodgskin `_. Internal Changes ~~~~~~~~~~~~~~~~