Skip to content

Commit 5588e0a

Browse files
committed
changed according to comments
1 parent 2a2d63f commit 5588e0a

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

pandas/io/formats/printing.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,21 +363,29 @@ def best_len(values):
363363
# adjust all values to max length if needed
364364
if is_justify:
365365
if line_break_each_value:
366+
# Justify each string in the values of head and tail, so the
367+
# strings will right align when head and tail are stacked
368+
# vertically.
366369
head, tail = _justify(head, tail)
367370
elif (is_truncated or not (len(', '.join(head)) < display_width and
368371
len(', '.join(tail)) < display_width)):
372+
# Each string in head and tail should align with each other
369373
max_length = max(best_len(head), best_len(tail))
370374
head = [x.rjust(max_length) for x in head]
371375
tail = [x.rjust(max_length) for x in tail]
372376
# If we are not truncated and we are only a single
373377
# line, then don't justify
374378

375379
if line_break_each_value:
376-
# truncate vertically if wider than max_space
380+
# Now head and tail are of type List[Tuple[str]]. Below we
381+
# convert them into List[str], so there will be one string per
382+
# value. Also truncate items horizontally if wider than
383+
# max_space
377384
max_space = display_width - len(space2)
378-
item = tail[0]
379-
for max_items in reversed(range(1, len(item) + 1)):
380-
if len(_pprint_seq(item, max_seq_items=max_items)) < max_space:
385+
value = tail[0]
386+
for max_items in reversed(range(1, len(value) + 1)):
387+
pprinted_seq = _pprint_seq(value, max_seq_items=max_items)
388+
if len(pprinted_seq) < max_space:
381389
break
382390
head = [_pprint_seq(x, max_seq_items=max_items) for x in head]
383391
tail = [_pprint_seq(x, max_seq_items=max_items) for x in tail]

0 commit comments

Comments
 (0)