Join strings with optional cropping for summarization. Parameters ---------- data : list List of strings to join. edgeitems : int or None, optional If specified, crops the list to show only the first and last `edgeitems` elements with "..." in between. If Non
(data, edgeitems=None, sep=", ", force_ellipsis=False)
| 23 | |
| 24 | |
| 25 | def _join_string(data, edgeitems=None, sep=", ", force_ellipsis=False): |
| 26 | """Join strings with optional cropping for summarization. |
| 27 | |
| 28 | Parameters |
| 29 | ---------- |
| 30 | data : list |
| 31 | List of strings to join. |
| 32 | edgeitems : int or None, optional |
| 33 | If specified, crops the list to show only the first and last `edgeitems` elements |
| 34 | with "..." in between. If None, shows all elements. Default: None. |
| 35 | sep : str, optional |
| 36 | Separator to use when joining strings. Default: ", ". |
| 37 | force_ellipsis : bool, optional |
| 38 | If True and edgeitems is not None, forces ellipsis insertion at position edgeitems |
| 39 | regardless of list length. Useful when data is pre-cropped. Default: False. |
| 40 | |
| 41 | Returns |
| 42 | ------- |
| 43 | str |
| 44 | Joined string, optionally with summarization. |
| 45 | """ |
| 46 | if edgeitems is not None and force_ellipsis: |
| 47 | # Force ellipsis at edgeitems position for pre-cropped data |
| 48 | data = data[:edgeitems] + ["..."] + data[edgeitems:] |
| 49 | elif edgeitems is not None and len(data) > 2 * edgeitems + 1: |
| 50 | # Crop and insert ellipsis |
| 51 | data = data[:edgeitems] + ["..."] + data[-edgeitems:] |
| 52 | return sep.join(data) |
| 53 | |
| 54 | |
| 55 | class TensorAdapter(Protocol): |
no outgoing calls
no test coverage detected