Skip to content

Commit e29aeb9

Browse files
committed
implement option 1: separate with just newlines
1 parent ae74cc6 commit e29aeb9

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

xarray/core/formatting.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -419,15 +419,18 @@ def inline_index_repr(index, max_width=None):
419419
return repr_
420420

421421

422-
def summarize_index(name: Hashable, index, col_width: int, max_width: int = None):
422+
def summarize_index(
423+
names: tuple[Hashable], index, col_width: int, max_width: int = None
424+
):
423425
if max_width is None:
424426
max_width = OPTIONS["display_width"]
425427

426-
preformatted = pretty_print(f" {name} ", col_width)
428+
preformatted = [pretty_print(f" {name} ", col_width) for name in names]
427429

428-
index_width = max_width - len(preformatted)
430+
head, *tail = preformatted
431+
index_width = max_width - len(head)
429432
repr_ = inline_index_repr(index, max_width=index_width)
430-
return preformatted + repr_
433+
return "\n".join([head + repr_] + [line.rstrip() for line in tail])
431434

432435

433436
def filter_nondefault_indexes(indexes, filter_indexes):
@@ -446,18 +449,10 @@ def filter_nondefault_indexes(indexes, filter_indexes):
446449

447450

448451
def indexes_repr(indexes, max_rows=None):
449-
def format_names(names):
450-
if len(names) == 1:
451-
return str(names[0])
452-
else:
453-
return f"[{', '.join(str(n) for n in names)}]"
454-
455-
indexes_ = {format_names(names): idx for names, idx in indexes.items()}
456-
457-
col_width = _calculate_col_width(indexes_)
452+
col_width = _calculate_col_width(chain.from_iterable(indexes))
458453

459454
return _mapping_repr(
460-
indexes_,
455+
indexes,
461456
"Indexes",
462457
summarize_index,
463458
"display_expand_indexes",

0 commit comments

Comments
 (0)