diff --git a/xarray/core/formatting.py b/xarray/core/formatting.py index e7f2a80caa5..3e23e41ff93 100644 --- a/xarray/core/formatting.py +++ b/xarray/core/formatting.py @@ -447,7 +447,7 @@ def coords_repr(coords: AbstractCoordinates, col_width=None, max_rows=None): def inherited_coords_repr(node: DataTree, col_width=None, max_rows=None): - coords = _inherited_vars(node._coord_variables) + coords = inherited_vars(node._coord_variables) if col_width is None: col_width = _calculate_col_width(coords) return _mapping_repr( @@ -1075,7 +1075,7 @@ def diff_datatree_repr(a: DataTree, b: DataTree, compat): return "\n\n".join(summary) -def _inherited_vars(mapping: ChainMap) -> dict: +def inherited_vars(mapping: ChainMap) -> dict: return {k: v for k, v in mapping.parents.items() if k not in mapping.maps[0]} @@ -1085,7 +1085,7 @@ def _datatree_node_repr(node: DataTree, show_inherited: bool) -> str: col_width = _calculate_col_width(node.variables) max_rows = OPTIONS["display_max_rows"] - inherited_coords = _inherited_vars(node._coord_variables) + inherited_coords = inherited_vars(node._coord_variables) # Only show dimensions if also showing a variable or coordinates section. show_dims = ( diff --git a/xarray/core/formatting_html.py b/xarray/core/formatting_html.py index e0a461caea7..d0cb7c30e91 100644 --- a/xarray/core/formatting_html.py +++ b/xarray/core/formatting_html.py @@ -9,6 +9,7 @@ from typing import TYPE_CHECKING from xarray.core.formatting import ( + inherited_vars, inline_index_repr, inline_variable_array_repr, short_data_repr, @@ -248,7 +249,6 @@ def array_section(obj) -> str: expand_option_name="display_expand_coords", ) - datavar_section = partial( _mapping_section, name="Data variables", @@ -382,16 +382,40 @@ def summarize_datatree_children(children: Mapping[str, DataTree]) -> str: expand_option_name="display_expand_groups", ) +inherited_coord_section = partial( + _mapping_section, + name="Inherited coordinates", + details_func=summarize_coords, + max_items_collapse=25, + expand_option_name="display_expand_coords", +) + + +def datatree_node_repr(group_title: str, node: DataTree, show_inherited=False) -> str: + from xarray.core.coordinates import Coordinates -def datatree_node_repr(group_title: str, dt: DataTree) -> str: header_components = [f"