Returns a succinct summary of an object as a string
(x, timedelta_format=None, quote_strings=True)
| 184 | |
| 185 | |
| 186 | def 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 | |
| 207 | def format_items(x): |
no test coverage detected
searching dependent graphs…