Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 89f9205

Browse files
committed
rename num_rows etc to max_rows for clarity
It can be the case when calculating row-first that the number of columns ends up allowing all cells to be accomodated in fewer rows. For example, if you have 6 items, and set nrows=4, then ncols=2, but 6 items can be accomodated in 3 rows.
1 parent cafd7d4 commit 89f9205

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

IPython/utils/text.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -618,28 +618,28 @@ def parse(self, fmt_string):
618618
# Utils to columnize a list of string
619619
#-----------------------------------------------------------------------------
620620

621-
def _col_chunks(l, nrows, row_first=False):
622-
"""Yield successive nrows-sized column chunks from l."""
621+
def _col_chunks(l, max_rows, row_first=False):
622+
"""Yield successive max_rows-sized column chunks from l."""
623623
if row_first:
624-
ncols = (len(l) // nrows) + (len(l) % nrows > 0)
624+
ncols = (len(l) // max_rows) + (len(l) % max_rows > 0)
625625
for i in py3compat.xrange(ncols):
626626
yield [l[j] for j in py3compat.xrange(i, len(l), ncols)]
627627
else:
628-
for i in py3compat.xrange(0, len(l), nrows):
629-
yield l[i:(i + nrows)]
628+
for i in py3compat.xrange(0, len(l), max_rows):
629+
yield l[i:(i + max_rows)]
630630

631631

632632
def _find_optimal(rlist, row_first=False, separator_size=2, displaywidth=80):
633633
"""Calculate optimal info to columnize a list of string"""
634-
for nrow in range(1, len(rlist) + 1):
635-
col_widths = list(map(max, _col_chunks(rlist, nrow, row_first)))
634+
for max_rows in range(1, len(rlist) + 1):
635+
col_widths = list(map(max, _col_chunks(rlist, max_rows, row_first)))
636636
sumlength = sum(col_widths)
637637
ncols = len(col_widths)
638638
if sumlength + separator_size * (ncols - 1) <= displaywidth:
639639
break
640640
return {'num_columns': ncols,
641641
'optimal_separator_width': (displaywidth - sumlength) / (ncols - 1) if (ncols - 1) else 0,
642-
'num_rows': nrow,
642+
'max_rows': max_rows,
643643
'column_widths': col_widths
644644
}
645645

@@ -685,8 +685,8 @@ def compute_item_matrix(items, row_first=False, empty=None, *args, **kwargs) :
685685
686686
num_columns
687687
number of columns
688-
num_rows
689-
number of rows
688+
max_rows
689+
maximum number of rows (final number may be less)
690690
column_widths
691691
list of with of each columns
692692
optimal_separator_width
@@ -707,10 +707,10 @@ def compute_item_matrix(items, row_first=False, empty=None, *args, **kwargs) :
707707
{'num_columns': 3,
708708
'column_widths': [5, 1, 1],
709709
'optimal_separator_width': 2,
710-
'num_rows': 5})
710+
'max_rows': 5})
711711
"""
712712
info = _find_optimal(list(map(len, items)), row_first, *args, **kwargs)
713-
nrow, ncol = info['num_rows'], info['num_columns']
713+
nrow, ncol = info['max_rows'], info['num_columns']
714714
if row_first:
715715
return ([[_get_or_default(items, r * ncol + c, default=empty) for c in range(ncol)] for r in range(nrow)], info)
716716
else:

0 commit comments

Comments
 (0)