Skip to content

Commit 23a200b

Browse files
committed
set DISPLAY_WIDTH to 80 by default + moved extraction of maxwidth and precision values from options in table2str()
1 parent 434f86a commit 23a200b

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

larray/core/array.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2279,10 +2279,8 @@ def __str__(self):
22792279
return 'LArray([])'
22802280
else:
22812281
maxlines = OPTIONS[MAXLINES] if OPTIONS[MAXLINES] is not None else 200
2282-
maxwidth = OPTIONS[DISPLAY_WIDTH]
2283-
precision = OPTIONS[DISPLAY_PRECISION]
22842282
table = list(self.as_table(maxlines))
2285-
return table2str(table, 'nan', maxwidth=maxwidth, keepcols=self.ndim - 1, precision=precision)
2283+
return table2str(table, 'nan', keepcols=self.ndim - 1)
22862284
__repr__ = __str__
22872285

22882286
def __iter__(self):

larray/tests/test_array.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,8 @@ def test_str(small_array, array):
309309
115 A21 F 153105.0 153106.0 153107.0"""
310310
# too many columns
311311
assert str(array['P01', 'A11', 'M']) == """\
312-
age 0 1 2 3 4 5 6 7 8 ... \
313-
106 107 108 109 110 111 112 113 114 115
314-
0.0 1320.0 2640.0 3960.0 5280.0 6600.0 7920.0 9240.0 10560.0 ... \
315-
139920.0 141240.0 142560.0 143880.0 145200.0 146520.0 147840.0 149160.0 150480.0 151800.0"""
312+
age 0 1 2 ... 112 113 114 115
313+
0.0 1320.0 2640.0 ... 147840.0 149160.0 150480.0 151800.0"""
316314

317315
arr = LArray([0, ''], Axis(['a0', ''], 'a'))
318316
assert str(arr) == "a a0 \n 0 "

larray/util/misc.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,21 @@ def get_min_width(table, index):
133133
return max(longest_word(row[index]) for row in table)
134134

135135

136-
def table2str(table, missing, summarize=True, maxwidth=80, numedges='auto', sep=' ', cont='...',
136+
def table2str(table, missing, summarize=True, maxwidth=None, numedges='auto', sep=' ', cont='...',
137137
keepcols=0, precision=None):
138138
"""
139139
table is a list of lists
140140
:type table: list of list
141141
"""
142142
if not table:
143143
return ''
144+
145+
from larray.util.options import OPTIONS, DISPLAY_WIDTH, DISPLAY_PRECISION
146+
if maxwidth is None:
147+
maxwidth = OPTIONS[DISPLAY_WIDTH]
148+
if precision is None:
149+
precision = OPTIONS[DISPLAY_PRECISION]
150+
144151
numcol = max(len(row) for row in table)
145152
# pad rows that have too few columns
146153
for row in table:

larray/util/options.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
OPTIONS = {
1616
DISPLAY_PRECISION: None,
17-
DISPLAY_WIDTH: 200,
17+
DISPLAY_WIDTH: 80,
1818
MAXLINES: None,
1919
EDGEITEMS: 5,
2020
}
@@ -46,8 +46,8 @@ class set_printoptions(object):
4646
4747
Currently supported options:
4848
49-
- ``precision``: number of digits of precision for floating point output. Defaults to 8.
50-
- ``display_width``: maximum display width for ``repr`` on xarray objects. Defaults to 80.
49+
- ``precision``: number of digits of precision for floating point output.
50+
- ``display_width``: maximum display width for ``repr`` on larray objects. Defaults to 80.
5151
- ``maxlines``: Maximum number of lines to show. Default behavior shows all lines.
5252
- ``edgeitems`` : if number of lines to display is greater than ``maxlines``, only the first and last
5353
``edgeitems`` lines are displayed. Only active if ``maxlines`` is not None. Defaults to 5.

0 commit comments

Comments
 (0)