Skip to content

Commit a08272f

Browse files
committed
added get_options function
1 parent 101aa75 commit a08272f

File tree

3 files changed

+39
-13
lines changed

3 files changed

+39
-13
lines changed

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_MAXLINES, DISPLAY_EDGEITEMS, DISPLAY_WIDTH, DISPLAY_PRECISION
68+
from larray.util.options import _OPTIONS, DISPLAY_MAXLINES, DISPLAY_EDGEITEMS, DISPLAY_WIDTH, DISPLAY_PRECISION
6969

7070

7171
def all(values, axis=None):
@@ -2278,9 +2278,9 @@ def __str__(self):
22782278
elif not len(self):
22792279
return 'LArray([])'
22802280
else:
2281-
table = list(self.as_table(OPTIONS[DISPLAY_MAXLINES], OPTIONS[DISPLAY_EDGEITEMS]))
2282-
return table2str(table, 'nan', maxwidth=OPTIONS[DISPLAY_WIDTH], keepcols=self.ndim - 1,
2283-
precision=OPTIONS[DISPLAY_PRECISION])
2281+
table = list(self.as_table(_OPTIONS[DISPLAY_MAXLINES], _OPTIONS[DISPLAY_EDGEITEMS]))
2282+
return table2str(table, 'nan', maxwidth=_OPTIONS[DISPLAY_WIDTH], keepcols=self.ndim - 1,
2283+
precision=_OPTIONS[DISPLAY_PRECISION])
22842284
__repr__ = __str__
22852285

22862286
def __iter__(self):

larray/tests/test_options.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import absolute_import, division, print_function
22
import pytest
33
import larray
4-
from larray.util.options import OPTIONS
54

65

76
def test_invalid_option_raises():
@@ -10,7 +9,7 @@ def test_invalid_option_raises():
109

1110

1211
def test_set_options_as_global():
13-
original_ops = OPTIONS.copy()
12+
original_ops = larray.get_options()
1413
arr = larray.ndtest((500, 100))
1514
larray.set_options(display_width=40, display_maxlines=10)
1615
expected = """\

larray/util/options.py

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

55

6-
__all__ = ['set_options']
6+
__all__ = ['set_options', 'get_options']
77

88

99
DISPLAY_PRECISION = 'display_precision'
@@ -12,7 +12,7 @@
1212
DISPLAY_EDGEITEMS = 'display_edgeitems'
1313

1414

15-
OPTIONS = {
15+
_OPTIONS = {
1616
DISPLAY_PRECISION: None,
1717
DISPLAY_WIDTH: 80,
1818
DISPLAY_MAXLINES: 200,
@@ -96,15 +96,42 @@ class set_options(object):
9696
def __init__(self, **kwargs):
9797
self.old = {}
9898
for k, v in kwargs.items():
99-
if k not in OPTIONS:
100-
raise ValueError('Argument {} is not in the set of valid options {}'.format(k, set(OPTIONS)))
99+
if k not in _OPTIONS:
100+
raise ValueError('Argument {} is not in the set of valid options {}'.format(k, set(_OPTIONS)))
101101
if k in _VALIDATORS:
102102
_VALIDATORS[k](v)
103-
self.old[k] = OPTIONS[k]
104-
OPTIONS.update(kwargs)
103+
self.old[k] = _OPTIONS[k]
104+
_OPTIONS.update(kwargs)
105105

106106
def __enter__(self):
107107
return
108108

109109
def __exit__(self, type, value, traceback):
110-
OPTIONS.update(self.old)
110+
_OPTIONS.update(self.old)
111+
112+
113+
def get_options():
114+
"""
115+
Return the current options.
116+
117+
Returns
118+
-------
119+
Dictionary of current print options with keys
120+
121+
- display_precision: int
122+
- display_width: int
123+
- display_maxlines: int
124+
- display_edgeitems : int
125+
126+
For a full description of these options, see :py:obj:`set_options`.
127+
128+
See Also
129+
--------
130+
set_options
131+
132+
Examples
133+
--------
134+
>>> get_options()
135+
{'display_precision': None, 'display_width': 80, 'display_maxlines': 200, 'display_edgeitems': 5}
136+
"""
137+
return _OPTIONS.copy()

0 commit comments

Comments
 (0)