MCPcopy Index your code
hub / github.com/pydata/xarray / _element_formatter

Function _element_formatter

xarray/core/formatting.py:575–627  ·  view source on GitHub ↗

Formats elements for better readability. Once it becomes wider than the display width it will create a newline and continue indented to col_width. Once there are more rows than the maximum displayed rows it will start removing rows. Parameters ---------- elements :

(
    elements: Collection[Hashable],
    col_width: int,
    max_rows: int | None = None,
    delimiter: str = ", ",
)

Source from the content-addressed store, hash-verified

573
574
575def _element_formatter(
576 elements: Collection[Hashable],
577 col_width: int,
578 max_rows: int | None = None,
579 delimiter: str = ", ",
580) -> str:
581 """
582 Formats elements for better readability.
583
584 Once it becomes wider than the display width it will create a newline and
585 continue indented to col_width.
586 Once there are more rows than the maximum displayed rows it will start
587 removing rows.
588
589 Parameters
590 ----------
591 elements : Collection of hashable
592 Elements to join together.
593 col_width : int
594 The width to indent to if a newline has been made.
595 max_rows : int, optional
596 The maximum number of allowed rows. The default is None.
597 delimiter : str, optional
598 Delimiter to use between each element. The default is ", ".
599 """
600 elements_len = len(elements)
601 out = [""]
602 length_row = 0
603 for i, v in enumerate(elements):
604 delim = delimiter if i < elements_len - 1 else ""
605 v_delim = f"{v}{delim}"
606 length_element = len(v_delim)
607 length_row += length_element
608
609 # Create a new row if the next elements makes the print wider than
610 # the maximum display width:
611 if col_width + length_row > OPTIONS["display_width"]:
612 out[-1] = out[-1].rstrip() # Remove trailing whitespace.
613 out.append("\n" + pretty_print("", col_width) + v_delim)
614 length_row = length_element
615 else:
616 out[-1] += v_delim
617
618 # If there are too many rows of dimensions trim some away:
619 if max_rows and (len(out) > max_rows):
620 first_rows = calc_max_rows_first(max_rows)
621 last_rows = calc_max_rows_last(max_rows)
622 out = (
623 out[:first_rows]
624 + ["\n" + pretty_print("", col_width) + "..."]
625 + (out[-last_rows:] if max_rows > 1 else [])
626 )
627 return "".join(out)
628
629
630def dim_summary_limited(

Callers 2

dim_summary_limitedFunction · 0.85
unindexed_dims_reprFunction · 0.85

Calls 5

pretty_printFunction · 0.85
calc_max_rows_firstFunction · 0.85
calc_max_rows_lastFunction · 0.85
rstripMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…