Returns a succinct summaries of all items in a sequence as strings
(x)
| 205 | |
| 206 | |
| 207 | def 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 | |
| 227 | def format_array_flat(array, max_width: int): |
no test coverage detected
searching dependent graphs…