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

Function format_item

xarray/core/formatting.py:186–204  ·  view source on GitHub ↗

Returns a succinct summary of an object as a string

(x, timedelta_format=None, quote_strings=True)

Source from the content-addressed store, hash-verified

184
185
186def format_item(x, timedelta_format=None, quote_strings=True):
187 """Returns a succinct summary of an object as a string"""
188 if isinstance(x, PandasExtensionArray):
189 # We want to bypass PandasExtensionArray's repr here
190 # because its __repr__ is PandasExtensionArray(array=[...])
191 # and this function is only for single elements.
192 return str(x.array[0])
193 if isinstance(x, np.datetime64 | datetime):
194 return format_timestamp(x)
195 if isinstance(x, np.timedelta64 | timedelta):
196 return format_timedelta(x, timedelta_format=timedelta_format)
197 elif isinstance(x, str | bytes):
198 if hasattr(x, "dtype"):
199 x = x.item()
200 return repr(x) if quote_strings else x
201 elif hasattr(x, "dtype") and np.issubdtype(x.dtype, np.floating) and x.shape == ():
202 return f"{x.item():.4}"
203 else:
204 return str(x)
205
206
207def format_items(x):

Callers 3

_nicetitleFunction · 0.90
_title_for_sliceMethod · 0.90
format_itemsFunction · 0.85

Calls 2

format_timestampFunction · 0.85
format_timedeltaFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…