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

Function summarize_variable

xarray/core/formatting.py:328–361  ·  view source on GitHub ↗

Summarize a variable in one line, e.g., for the Dataset.__repr__.

(
    name: Hashable,
    var: Variable,
    col_width: int | None = None,
    max_width: int | None = None,
    is_index: bool = False,
)

Source from the content-addressed store, hash-verified

326
327
328def summarize_variable(
329 name: Hashable,
330 var: Variable,
331 col_width: int | None = None,
332 max_width: int | None = None,
333 is_index: bool = False,
334):
335 """Summarize a variable in one line, e.g., for the Dataset.__repr__."""
336 variable = getattr(var, "variable", var)
337
338 if max_width is None:
339 max_width_options = OPTIONS["display_width"]
340 if not isinstance(max_width_options, int):
341 raise TypeError(f"`max_width` value of `{max_width}` is not a valid int")
342 else:
343 max_width = max_width_options
344
345 marker = "*" if is_index else " "
346 first_col = f" {marker} {name} "
347 if col_width is not None:
348 first_col = pretty_print(first_col, col_width)
349
350 if variable.dims:
351 dims_str = ", ".join(map(str, variable.dims))
352 dims_str = f"({dims_str}) "
353 else:
354 dims_str = ""
355
356 front_str = f"{first_col}{dims_str}{variable.dtype} {render_human_readable_nbytes(variable.nbytes)} "
357
358 values_width = max_width - len(front_str)
359 values_str = inline_variable_array_repr(variable, values_width)
360
361 return f"{front_str}{values_str}"
362
363
364def summarize_attr(key, value, col_width=None):

Callers

nothing calls this directly

Calls 4

pretty_printFunction · 0.85
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…