-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add _repr_inline_ documentation to CustomIndex docs
#11046
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add _repr_inline_ documentation to CustomIndex docs
#11046
Conversation
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
|
Thank you for opening this pull request! It may take us a few days to respond here, so thank you for being patient. |
jsignell
left a comment
There was a problem hiding this 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: | ||
| dims = [idx.dim for idx in self._xy_indexes.values()] | ||
| return f"RasterIndex (dims={dims})" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return f"RasterIndex (dims={dims})" | |
| return f"{self.__class__.__name__} (dims={dims})" |
| def _repr_inline_(self, max_width: int) -> str: | ||
| # Return a concise representation | ||
| return f"MyIndex (size={len(self._data)})" |
There was a problem hiding this comment.
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:
| return f"MyIndex (size={len(self._data)})" | |
| return f"{self.__class__.__name__} (size={len(self._data)})" |
ianhi
left a comment
There was a problem hiding this 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.
| .. code-block:: none | ||
| <xarray.DataArray (x: 10)> | ||
| ... | ||
| Indexes: | ||
| x MyIndex (size=10) |
There was a problem hiding this comment.
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
| - ``RangeIndex`` returns: ``RangeIndex (start=0, stop=1, step=0.1)`` | ||
| - ``NDPointIndex`` returns: ``NDPointIndex (KDTree)`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If possible to link to the source code for these (ideally linked to the release) that would be amazing. but no worries if that's too difficult ot get working with auto updating permalinks.
| The ``_repr_inline_`` method receives a ``max_width`` argument (number of | ||
| characters) that can be used to truncate the output if needed: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The phrasing here could be a bit more precise. I think this is either xarray telling us that we are going to be truncated, so we better fit it all in there, or telling us that we must truncate. I'm actually not sure what the behavior is and this would be a great place to discuss it.
…e block, improve phrasing
Closes #11036
As noted in #11035, the custom index docs page was missing information about
_repr_inline_.This PR adds:
_repr_inline_methodmax_widthparameterRangeIndexandNDPointIndexRasterIndexexample to include a_repr_inline_implementation