MCPcopy
hub / github.com/pydata/xarray / _datatree_node_sections

Function _datatree_node_sections

xarray/core/formatting_html.py:405–455  ·  view source on GitHub ↗
(node: DataTree, root: bool)

Source from the content-addressed store, hash-verified

403
404
405def _datatree_node_sections(node: DataTree, root: bool) -> tuple[list[str], int]:
406 from xarray.core.coordinates import Coordinates
407
408 ds = node._to_dataset_view(rebuild_dims=False, inherit=True)
409 node_coords = node.to_dataset(inherit=False).coords
410
411 # use this class to get access to .xindexes property
412 inherited_coords = Coordinates(
413 coords=inherited_vars(node._coord_variables),
414 indexes=inherited_vars(node._indexes),
415 )
416
417 # Only show dimensions if also showing a variable or coordinates section.
418 show_dims = node_coords or (root and inherited_coords) or ds.data_vars
419
420 display_default_indexes = _get_boolean_with_default(
421 "display_default_indexes", False
422 )
423 xindexes = filter_nondefault_indexes(
424 _get_indexes_dict(ds.xindexes), not display_default_indexes
425 )
426
427 sections = []
428 if show_dims:
429 sections.append(dim_section(ds))
430 if node_coords:
431 sections.append(coord_section(node_coords))
432 if root and inherited_coords:
433 sections.append(inherited_coord_section(inherited_coords))
434 if ds.data_vars:
435 sections.append(datavar_section(ds.data_vars))
436 if xindexes:
437 sections.append(index_section(xindexes))
438 if ds.attrs:
439 sections.append(attr_section(ds.attrs))
440
441 displayed_line_count = (
442 len(node.children)
443 + int(bool(show_dims))
444 + int(bool(node_coords))
445 + len(node_coords)
446 + int(root) * (int(bool(inherited_coords)) + len(inherited_coords))
447 + int(bool(ds.data_vars))
448 + len(ds.data_vars)
449 + int(bool(xindexes))
450 + len(xindexes)
451 + int(bool(ds.attrs))
452 + len(ds.attrs)
453 )
454
455 return sections, displayed_line_count
456
457
458def _tree_item_count(node: DataTree, cache: dict[int, int]) -> int:

Callers 1

_build_datatree_displaysFunction · 0.85

Calls 8

CoordinatesClass · 0.90
inherited_varsFunction · 0.90
dim_sectionFunction · 0.85
_to_dataset_viewMethod · 0.80
_get_indexes_dictFunction · 0.70
to_datasetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…