Show inherited indexes separately in DataTree repr - #11561
Open
mokashang wants to merge 1 commit into
Open
Conversation
DataTree already distinguishes ``Coordinates:`` (defined at this node) from ``Inherited coordinates:`` (inherited from an ancestor), but its text and HTML reprs lump every index into a single ``Indexes:`` section. That makes it easy to mistake an inherited index for one added at the current node, and the TODO in ``_datatree_node_repr`` called this out. Split the indexes the same way coordinates are split: * ``Indexes:`` shows only indexes whose coord names come from ``node._node_indexes``. * ``Inherited indexes:`` shows only indexes whose coord names all come from ``inherited_vars(node._indexes)``. Like ``Inherited coordinates:`` it is only rendered when ``root=True``, so the whole-tree repr still attributes each inherited index to the ancestor that defines it and does not repeat it on every descendant. The split is done by ``_split_node_indexes``, which walks ``_get_indexes_dict(node.xindexes)`` once and buckets each ``(names, Index)`` pair by whether every name in the group is inherited. That preserves the existing grouping behavior for indexes that span multiple coordinates (e.g. ``PandasMultiIndex``). ``filter_nondefault_indexes`` runs on each bucket independently so the ``display_default_indexes`` option keeps its current meaning. The HTML ``_datatree_node_sections`` line-count accounting is updated to match the new section. Fixes pydata#10578
|
Thank you for opening this pull request! It may take us a few days to respond here, so thank you for being patient. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
DataTree already distinguishes
Coordinates:(defined at this node)from
Inherited coordinates:(inherited from an ancestor), but itstext and HTML reprs lump every index into a single
Indexes:section.That makes it easy to mistake an inherited index for one added at the
current node, and there was a
TODOin_datatree_node_reprcalling this out.
Fix: split the indexes the same way coordinates are split.
Indexes:shows only indexes whose coord names come fromnode._node_indexes.Inherited indexes:shows only indexes whose coord names all comefrom
inherited_vars(node._indexes). LikeInherited coordinates:,it is only rendered when
root=True, so the whole-tree repr stillattributes each inherited index to the ancestor that defines it and
does not repeat it on every descendant.
Both the text repr (
_datatree_node_reprinformatting.py) andthe HTML repr (
_datatree_node_sectionsinformatting_html.py)use the same split helper,
_split_node_indexes, which walks_get_indexes_dict(node.xindexes)once and buckets each(names, Index)pair by whether every name in the group is inherited. Thatpreserves the existing grouping behaviour for indexes that span
multiple coordinates (e.g.
PandasMultiIndex).filter_nondefault_indexesis applied independently to each bucket,so the
display_default_indexesoption keeps its current meaning.The HTML
displayed_line_countaccounting is updated to include thenew section.
Before, for a tree where the child inherits a non-default
RangeIndexfrom its parent, the child's repr looked like this:
After:
Checklist
whats-new.rstapi.rst