6565from 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
6869
6970
7071def all (values , axis = None ):
@@ -2277,8 +2278,12 @@ def __str__(self):
22772278 elif not len (self ):
22782279 return 'LArray([])'
22792280 else :
2280- table = list (self .as_table (maxlines = 200 , edgeitems = 5 ))
2281- return table2str (table , 'nan' , fullinfo = True , maxwidth = 200 , keepcols = self .ndim - 1 )
2281+ maxlines = OPTIONS [MAXLINES ] if OPTIONS [MAXLINES ] is not None else 200
2282+ maxwidth = OPTIONS [DISPLAY_WIDTH ]
2283+ precision = OPTIONS [DISPLAY_PRECISION ]
2284+ table = list (self .as_table (maxlines ))
2285+ return table2str (table , 'nan' , fullinfo = True , maxwidth = maxwidth , keepcols = self .ndim - 1 ,
2286+ precision = precision )
22822287 __repr__ = __str__
22832288
22842289 def __iter__ (self ):
@@ -2287,8 +2292,9 @@ def __iter__(self):
22872292 def __contains__ (self , key ):
22882293 return any (key in axis for axis in self .axes )
22892294
2290- def as_table (self , maxlines = None , edgeitems = 5 , light = False , wide = True , value_name = 'value' ):
2291- """
2295+ def as_table (self , maxlines = None , edgeitems = None , light = False , wide = True , value_name = 'value' ):
2296+ r"""as_table(maxlines=None, edgeitems=5, light=False, wide=True, value_name='value')
2297+
22922298 Generator. Returns next line of the table representing an array.
22932299
22942300 Parameters
@@ -2300,6 +2306,9 @@ def as_table(self, maxlines=None, edgeitems=5, light=False, wide=True, value_nam
23002306 only the first and last `edgeitems` lines are displayed.
23012307 Only active if `maxlines` is not None.
23022308 Equals to 5 by default.
2309+ light: bool, optional
2310+ Whether or not printing the array in the same way as a pandas DataFrame with a MultiIndex
2311+ (see example below). Defaults to False.
23032312 wide : boolean, optional
23042313 Whether or not to write arrays in "wide" format. If True, arrays are exported with the last axis
23052314 represented horizontally. If False, arrays are exported in "narrow" format: one column per axis plus one
@@ -2317,13 +2326,13 @@ def as_table(self, maxlines=None, edgeitems=5, light=False, wide=True, value_nam
23172326 --------
23182327 >>> arr = ndtest((2, 2, 3))
23192328 >>> list(arr.as_table()) # doctest: +NORMALIZE_WHITESPACE
2320- [['a', 'b\\ \\ c', 'c0', 'c1', 'c2'],
2329+ [['a', 'b\\c', 'c0', 'c1', 'c2'],
23212330 ['a0', 'b0', 0, 1, 2],
23222331 ['a0', 'b1', 3, 4, 5],
23232332 ['a1', 'b0', 6, 7, 8],
23242333 ['a1', 'b1', 9, 10, 11]]
23252334 >>> list(arr.as_table(light=True)) # doctest: +NORMALIZE_WHITESPACE
2326- [['a', 'b\\ \\ c', 'c0', 'c1', 'c2'],
2335+ [['a', 'b\\c', 'c0', 'c1', 'c2'],
23272336 ['a0', 'b0', 0, 1, 2],
23282337 ['', 'b1', 3, 4, 5],
23292338 ['a1', 'b0', 6, 7, 8],
@@ -2346,6 +2355,12 @@ def as_table(self, maxlines=None, edgeitems=5, light=False, wide=True, value_nam
23462355 if not self .ndim :
23472356 return
23482357
2358+ # get default options
2359+ if maxlines is None :
2360+ maxlines = OPTIONS [MAXLINES ]
2361+ if edgeitems is None :
2362+ edgeitems = OPTIONS [EDGEITEMS ]
2363+
23492364 # ert unit geo\time 2012 2011 2010
23502365 # NEER27 I05 AT 101.41 101.63 101.63
23512366 # NEER27 I05 AU 134.86 125.29 117.08
@@ -2398,7 +2413,9 @@ def as_table(self, maxlines=None, edgeitems=5, light=False, wide=True, value_nam
23982413 yield list (tick ) + dataline .tolist ()
23992414
24002415 def dump (self , header = True , wide = True , value_name = 'value' ):
2401- """Dump array as a 2D nested list
2416+ """dump(header=True, wide=True, value_name='value')
2417+
2418+ Dump array as a 2D nested list
24022419
24032420 Parameters
24042421 ----------
0 commit comments