Skip to content

Commit 7a29216

Browse files
committed
Address reviewer comments: use class name dynamically, jupyter-execute block, improve phrasing
1 parent b704e91 commit 7a29216

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,20 @@ just the class name. You can customize this by implementing the
138138
string representation of the index.
139139

140140
The ``_repr_inline_`` method receives a ``max_width`` argument (number of
141-
characters) that can be used to truncate the output if needed:
141+
characters) that indicates the available space for the representation. If the
142+
representation exceeds this width, it should be truncated:
142143

143-
.. code-block:: python
144+
.. jupyter-execute::
145+
146+
from xarray import Index
144147

145148
class MyIndex(Index):
146149
def __init__(self, data):
147150
self._data = data
148151

149152
def _repr_inline_(self, max_width: int) -> str:
150153
# Return a concise representation
151-
return f"MyIndex (size={len(self._data)})"
154+
return f"{self.__class__.__name__} (size={len(self._data)})"
152155

153156
Here are some examples from Xarray's built-in indexes:
154157

@@ -237,7 +240,7 @@ regularly spaced 2-dimensional data) that internally relies on two
237240
238241
def _repr_inline_(self, max_width: int) -> str:
239242
dims = [idx.dim for idx in self._xy_indexes.values()]
240-
return f"RasterIndex (dims={dims})"
243+
return f"{self.__class__.__name__} (dims={dims})"
241244
242245
243246
This basic index only supports label-based selection. Providing a full-featured

0 commit comments

Comments
 (0)