Skip to content

Commit 847cebc

Browse files
committed
renamed set_printoptions() as set_options() + renamed MAXLINES and EDGEITEMS as DISPLAY_MAXLINES and DISPLAY_EDGEITEMS + updated doctests of set_options
1 parent 23a200b commit 847cebc

File tree

5 files changed

+65
-64
lines changed

5 files changed

+65
-64
lines changed

doc/source/api.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ Miscellaneous
664664
from_frame
665665
from_series
666666
get_example_filepath
667-
set_printoptions
667+
set_options
668668
labels_array
669669
union
670670
stack

doc/source/changes/version_0_30.rst.inc

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -224,38 +224,38 @@ Miscellaneous improvements
224224
* implemented :py:obj:`LArray.reverse()` method to reverse one or several axes of an array (closes :issue:`631`).
225225

226226

227-
* added :py:obj:`set_printoptions` allowing to set options for printing arrays within a ``with`` block or globally:
227+
* added :py:obj:`set_options` allowing to set options for larray within a ``with`` block or globally:
228228

229229
>>> from larray import *
230230
>>> arr = ndtest((500, 100), dtype=float) / 3
231231

232232
You can use ``set_options`` either as a context manager:
233233

234-
>>> with set_printoptions(display_width=60, edgeitems=2, precision=2):
234+
>>> with set_options(display_width=100, display_edgeitems=2):
235235
... print(arr)
236-
a\b b0 b1 ... b98 b99
237-
a0 0 0.33 ... 32.67 33
238-
a1 33.33 33.67 ... 66 66.33
239-
... ... ... ... ... ...
240-
a498 16600 16600.33 ... 16632.67 16633
241-
a499 16633.33 16633.67 ... 16666 16666.33
236+
a\b b0 b1 ... b98 b99
237+
a0 0.0 0.3333333333333333 ... 32.666666666666664 33.0
238+
a1 33.333333333333336 33.666666666666664 ... 66.0 66.33333333333333
239+
... ... ... ... ... ...
240+
a498 16600.0 16600.333333333332 ... 16632.666666666668 16633.0
241+
a499 16633.333333333332 16633.666666666668 ... 16666.0 16666.333333333332
242242

243243
Or to set global options:
244244

245-
>>> set_printoptions(display_width=40, maxlines=10, precision=2)
246-
>>> print(arr)
247-
a\b b0 ... b99
248-
a0 0 ... 33
249-
a1 33.33 ... 66.33
250-
a2 66.67 ... 99.67
251-
a3 100 ... 133
252-
a4 133.33 ... 166.33
253-
... ... ... ...
254-
a495 16500 ... 16533
255-
a496 16533.33 ... 16566.33
256-
a497 16566.67 ... 16599.67
257-
a498 16600 ... 16633
258-
a499 16633.33 ... 16666.33
245+
>>> set_options(display_maxlines=10, display_precision=2) # doctest: +SKIP
246+
>>> print(arr) # doctest: +SKIP
247+
a\b b0 b1 b2 ... b97 b98 b99
248+
a0 0.00 0.33 0.67 ... 32.33 32.67 33.00
249+
a1 33.33 33.67 34.00 ... 65.67 66.00 66.33
250+
a2 66.67 67.00 67.33 ... 99.00 99.33 99.67
251+
a3 100.00 100.33 100.67 ... 132.33 132.67 133.00
252+
a4 133.33 133.67 134.00 ... 165.67 166.00 166.33
253+
... ... ... ... ... ... ... ...
254+
a495 16500.00 16500.33 16500.67 ... 16532.33 16532.67 16533.00
255+
a496 16533.33 16533.67 16534.00 ... 16565.67 16566.00 16566.33
256+
a497 16566.67 16567.00 16567.33 ... 16599.00 16599.33 16599.67
257+
a498 16600.00 16600.33 16600.67 ... 16632.33 16632.67 16633.00
258+
a499 16633.33 16633.67 16634.00 ... 16665.67 16666.00 16666.33
259259

260260
Closes :issue:`274`.
261261

larray/core/array.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
from larray.util.misc import (table2str, size2str, basestring, izip, rproduct, ReprString, duplicates,
6666
float_error_handler_factory, _isnoneslice, light_product, unique_list, common_type,
6767
renamed_to, deprecate_kwarg, LHDFStore, lazy_attribute)
68-
from larray.util.options import OPTIONS, DISPLAY_PRECISION, DISPLAY_WIDTH, MAXLINES, EDGEITEMS
68+
from larray.util.options import OPTIONS, DISPLAY_MAXLINES, DISPLAY_EDGEITEMS
6969

7070

7171
def all(values, axis=None):
@@ -2278,7 +2278,7 @@ def __str__(self):
22782278
elif not len(self):
22792279
return 'LArray([])'
22802280
else:
2281-
maxlines = OPTIONS[MAXLINES] if OPTIONS[MAXLINES] is not None else 200
2281+
maxlines = OPTIONS[DISPLAY_MAXLINES] if OPTIONS[DISPLAY_MAXLINES] is not None else 200
22822282
table = list(self.as_table(maxlines))
22832283
return table2str(table, 'nan', keepcols=self.ndim - 1)
22842284
__repr__ = __str__
@@ -2352,9 +2352,9 @@ def as_table(self, maxlines=None, edgeitems=None, light=False, wide=True, value_
23522352

23532353
# get default options
23542354
if maxlines is None:
2355-
maxlines = OPTIONS[MAXLINES]
2355+
maxlines = OPTIONS[DISPLAY_MAXLINES]
23562356
if edgeitems is None:
2357-
edgeitems = OPTIONS[EDGEITEMS]
2357+
edgeitems = OPTIONS[DISPLAY_EDGEITEMS]
23582358

23592359
# ert unit geo\time 2012 2011 2010
23602360
# NEER27 I05 AT 101.41 101.63 101.63

larray/tests/test_options.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
def test_invalid_option_raises():
88
with pytest.raises(ValueError):
9-
larray.set_printoptions(not_a_valid_options=True)
9+
larray.set_options(not_a_valid_options=True)
1010

1111

1212
def test_set_options_as_global():
1313
original_ops = OPTIONS.copy()
1414
arr = larray.ndtest((500, 100))
15-
larray.set_printoptions(display_width=40, maxlines=10)
15+
larray.set_options(display_width=40, display_maxlines=10)
1616
expected = """\
1717
a\\b b0 b1 ... b98 b99
1818
a0 0 1 ... 98 99
@@ -27,4 +27,4 @@ def test_set_options_as_global():
2727
a498 49800 49801 ... 49898 49899
2828
a499 49900 49901 ... 49998 49999"""
2929
assert str(arr) == expected
30-
larray.set_printoptions(**original_ops)
30+
larray.set_options(**original_ops)

larray/util/options.py

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
from larray.util.misc import basestring
44

55

6-
__all__ = ['set_printoptions']
6+
__all__ = ['set_options']
77

88

9-
DISPLAY_PRECISION = 'precision'
9+
DISPLAY_PRECISION = 'display_precision'
1010
DISPLAY_WIDTH = 'display_width'
11-
MAXLINES = 'maxlines'
12-
EDGEITEMS = 'edgeitems'
11+
DISPLAY_MAXLINES = 'display_maxlines'
12+
DISPLAY_EDGEITEMS = 'display_edgeitems'
1313

1414

1515
OPTIONS = {
1616
DISPLAY_PRECISION: None,
1717
DISPLAY_WIDTH: 80,
18-
MAXLINES: None,
19-
EDGEITEMS: 5,
18+
DISPLAY_MAXLINES: None,
19+
DISPLAY_EDGEITEMS: 5,
2020
}
2121

2222

@@ -35,22 +35,23 @@ def _positive_integer_or_none(value):
3535
_VALIDATORS = {
3636
DISPLAY_PRECISION: _positive_integer_or_none,
3737
DISPLAY_WIDTH: _positive_integer,
38-
MAXLINES: _positive_integer_or_none,
39-
EDGEITEMS: _positive_integer,
38+
DISPLAY_MAXLINES: _positive_integer_or_none,
39+
DISPLAY_EDGEITEMS: _positive_integer,
4040
}
4141

4242

4343
# idea taken from xarray. See xarray/core/options.py module for original implementation.
44-
class set_printoptions(object):
45-
r"""Set options for printing arrays in a controlled context.
44+
class set_options(object):
45+
r"""Set options for larray in a controlled context.
4646
4747
Currently supported options:
4848
49-
- ``precision``: number of digits of precision for floating point output.
49+
- ``display_precision``: number of digits of precision for floating point output.
5050
- ``display_width``: maximum display width for ``repr`` on larray objects. Defaults to 80.
51-
- ``maxlines``: Maximum number of lines to show. Default behavior shows all lines.
52-
- ``edgeitems`` : if number of lines to display is greater than ``maxlines``, only the first and last
53-
``edgeitems`` lines are displayed. Only active if ``maxlines`` is not None. Defaults to 5.
51+
- ``display_maxlines``: Maximum number of lines to show. Default behavior shows all lines.
52+
- ``display_edgeitems`` : if number of lines to display is greater than ``display_maxlines``,
53+
only the first and last ``display_edgeitems`` lines are displayed.
54+
Only active if ``display_maxlines`` is not None. Defaults to 5.
5455
5556
Examples
5657
--------
@@ -59,31 +60,31 @@ class set_printoptions(object):
5960
6061
You can use ``set_options`` either as a context manager:
6162
62-
>>> with set_printoptions(display_width=60, edgeitems=2, precision=2):
63+
>>> with set_options(display_width=100, display_edgeitems=2):
6364
... print(arr)
64-
a\b b0 b1 ... b98 b99
65-
a0 0.00 0.33 ... 32.67 33.00
66-
a1 33.33 33.67 ... 66.00 66.33
67-
... ... ... ... ... ...
68-
a498 16600.00 16600.33 ... 16632.67 16633.00
69-
a499 16633.33 16633.67 ... 16666.00 16666.33
65+
a\b b0 b1 ... b98 b99
66+
a0 0.0 0.3333333333333333 ... 32.666666666666664 33.0
67+
a1 33.333333333333336 33.666666666666664 ... 66.0 66.33333333333333
68+
... ... ... ... ... ...
69+
a498 16600.0 16600.333333333332 ... 16632.666666666668 16633.0
70+
a499 16633.333333333332 16633.666666666668 ... 16666.0 16666.333333333332
7071
7172
Or to set global options:
7273
73-
>>> set_printoptions(display_width=40, maxlines=10, precision=2) # doctest: +SKIP
74+
>>> set_options(display_maxlines=10, display_precision=2) # doctest: +SKIP
7475
>>> print(arr) # doctest: +SKIP
75-
a\b b0 ... b99
76-
a0 0.00 ... 33.00
77-
a1 33.33 ... 66.33
78-
a2 66.67 ... 99.67
79-
a3 100.00 ... 133.00
80-
a4 133.33 ... 166.33
81-
... ... ... ...
82-
a495 16500.00 ... 16533.00
83-
a496 16533.33 ... 16566.33
84-
a497 16566.67 ... 16599.67
85-
a498 16600.00 ... 16633.00
86-
a499 16633.33 ... 16666.33
76+
a\b b0 b1 b2 ... b97 b98 b99
77+
a0 0.00 0.33 0.67 ... 32.33 32.67 33.00
78+
a1 33.33 33.67 34.00 ... 65.67 66.00 66.33
79+
a2 66.67 67.00 67.33 ... 99.00 99.33 99.67
80+
a3 100.00 100.33 100.67 ... 132.33 132.67 133.00
81+
a4 133.33 133.67 134.00 ... 165.67 166.00 166.33
82+
... ... ... ... ... ... ... ...
83+
a495 16500.00 16500.33 16500.67 ... 16532.33 16532.67 16533.00
84+
a496 16533.33 16533.67 16534.00 ... 16565.67 16566.00 16566.33
85+
a497 16566.67 16567.00 16567.33 ... 16599.00 16599.33 16599.67
86+
a498 16600.00 16600.33 16600.67 ... 16632.33 16632.67 16633.00
87+
a499 16633.33 16633.67 16634.00 ... 16665.67 16666.00 16666.33
8788
"""
8889

8990
def __init__(self, **kwargs):

0 commit comments

Comments
 (0)