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

Function summarize_variable

xarray/core/formatting_html.py:83–117  ·  view source on GitHub ↗
(name, var, is_index=False, dtype=None)

Source from the content-addressed store, hash-verified

81
82
83def summarize_variable(name, var, is_index=False, dtype=None) -> str:
84 variable = var.variable if hasattr(var, "variable") else var
85
86 cssclass_idx = " class='xr-has-index'" if is_index else ""
87 dims_str = f"({', '.join(escape(dim) for dim in var.dims)})"
88 name = escape(str(name))
89 dtype = dtype or escape(str(var.dtype))
90
91 # "unique" ids required to expand/collapse subsections
92 attrs_id = "attrs-" + str(uuid.uuid4())
93 data_id = "data-" + str(uuid.uuid4())
94 disabled = "" if len(var.attrs) else "disabled"
95
96 preview = escape(inline_variable_array_repr(variable, 35))
97 attrs_ul = summarize_attrs(var.attrs)
98 data_repr = short_data_repr_html(variable)
99
100 attrs_icon = _icon("icon-file-text2")
101 data_icon = _icon("icon-database")
102
103 return (
104 f"<div class='xr-var-name'><span{cssclass_idx}>{name}</span></div>"
105 f"<div class='xr-var-dims'>{dims_str}</div>"
106 f"<div class='xr-var-dtype'>{dtype}</div>"
107 f"<div class='xr-var-preview xr-preview'>{preview}</div>"
108 f"<input id='{attrs_id}' class='xr-var-attrs-in' "
109 f"type='checkbox' {disabled}>"
110 f"<label for='{attrs_id}' title='Show/Hide attributes'>"
111 f"{attrs_icon}</label>"
112 f"<input id='{data_id}' class='xr-var-data-in' type='checkbox'>"
113 f"<label for='{data_id}' title='Show/Hide data repr'>"
114 f"{data_icon}</label>"
115 f"<div class='xr-var-attrs'>{attrs_ul}</div>"
116 f"<div class='xr-var-data'>{data_repr}</div>"
117 )
118
119
120def summarize_coords(variables) -> str:

Callers 2

summarize_coordsFunction · 0.70
summarize_varsFunction · 0.70

Calls 5

summarize_attrsFunction · 0.85
short_data_repr_htmlFunction · 0.85
_iconFunction · 0.85
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…