File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed
Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -138,17 +138,20 @@ just the class name. You can customize this by implementing the
138138string representation of the index.
139139
140140The ``_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
153156Here 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
You can’t perform that action at this time.
0 commit comments