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

Function format_items

xarray/core/formatting.py:207–224  ·  view source on GitHub ↗

Returns a succinct summaries of all items in a sequence as strings

(x)

Source from the content-addressed store, hash-verified

205
206
207def format_items(x):
208 """Returns a succinct summaries of all items in a sequence as strings"""
209 x = to_duck_array(x)
210 timedelta_format = "datetime"
211 if not isinstance(x, PandasExtensionArray) and np.issubdtype(
212 x.dtype, np.timedelta64
213 ):
214 x = astype(x, dtype="timedelta64[ns]")
215 day_part = x[~pd.isnull(x)].astype("timedelta64[D]").astype("timedelta64[ns]")
216 time_needed = x[~pd.isnull(x)] != day_part
217 day_needed = day_part != np.timedelta64(0, "ns")
218 if array_all(np.logical_not(day_needed)):
219 timedelta_format = "time"
220 elif array_all(np.logical_not(time_needed)):
221 timedelta_format = "date"
222
223 formatted = [format_item(xi, timedelta_format) for xi in x]
224 return formatted
225
226
227def format_array_flat(array, max_width: int):

Callers 1

format_array_flatFunction · 0.85

Calls 6

to_duck_arrayFunction · 0.90
astypeFunction · 0.90
array_allFunction · 0.90
format_itemFunction · 0.85
astypeMethod · 0.45
isnullMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…