Skip to content

Conversation

@sshekhar563
Copy link

Closes #11036

As noted in #11035, the custom index docs page was missing information about _repr_inline_.

This PR adds:

  • A new "Custom representation" section explaining the _repr_inline_ method
  • Documentation of the method signature with the max_width parameter
  • A code example showing how to implement it
  • Real-world examples from RangeIndex and NDPointIndex
  • Updated the RasterIndex example to include a _repr_inline_ implementation

Closes pydata#11036

- Add new 'Custom representation' section explaining _repr_inline_
- Document method signature with max_width parameter
- Include code example and real-world examples from RangeIndex/NDPointIndex
- Update RasterIndex example to include _repr_inline_ implementation
@welcome
Copy link

welcome bot commented Dec 22, 2025

Thank you for opening this pull request! It may take us a few days to respond here, so thank you for being patient.
If you have questions, some answers may be found in our contributing guidelines.

Copy link
Member

@jsignell jsignell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @sshekhar563! I just had one little suggestion.

def _repr_inline_(self, max_width: int) -> str:
# Return a concise representation
return f"MyIndex (size={len(self._data)})"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a little nitpick. Prefer to use class name rather than hardcoding:

Suggested change
return f"MyIndex (size={len(self._data)})"
return f"{self.__class__.__name__} (size={len(self._data)})"

Copy link
Contributor

@ianhi ianhi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great thanks @sshekhar563

I left a few suggestions but nothing crucial. I agree re the suggestion to use a classname instead of hardcoding.

Comment on lines 161 to 166
.. code-block:: none
<xarray.DataArray (x: 10)>
...
Indexes:
x MyIndex (size=10)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be a jupyter-execute block? to make sure this stays up to date

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sshekhar563 can you address this comment please

@sshekhar563 sshekhar563 requested a review from dcherian December 24, 2025 06:50
dcherian and others added 3 commits December 24, 2025 08:31
Co-authored-by: Julia Signell <jsignell@gmail.com>
Co-authored-by: Deepak Cherian <dcherian@users.noreply.github.com>
@sshekhar563
Copy link
Author

@dcherian My apologies for the oversight. I realized that the example block on line 165 was not updated in the previous commit. I’ve now revised the documentation to use a single, self-contained jupyter-execute block for the custom representation example. This ensures the output is generated dynamically and remains consistent with Xarray’s UI. Thank you for pointing this out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

📚 Add repr information to CustomIndex docs

4 participants