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_MAXLINES , DISPLAY_EDGEITEMS , DISPLAY_WIDTH , DISPLAY_PRECISION
6869
6970
7071def all (values , axis = None ):
@@ -2277,8 +2278,9 @@ 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+ 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 ])
22822284 __repr__ = __str__
22832285
22842286 def __iter__ (self ):
@@ -2287,19 +2289,22 @@ def __iter__(self):
22872289 def __contains__ (self , key ):
22882290 return any (key in axis for axis in self .axes )
22892291
2290- def as_table (self , maxlines = None , edgeitems = 5 , light = False , wide = True , value_name = 'value' ):
2291- """
2292+ def as_table (self , maxlines = - 1 , edgeitems = 5 , light = False , wide = True , value_name = 'value' ):
2293+ r """
22922294 Generator. Returns next line of the table representing an array.
22932295
22942296 Parameters
22952297 ----------
22962298 maxlines : int, optional
2297- Maximum number of lines to show.
2299+ Maximum number of lines to show. Defaults to -1 (all lines are shown).
22982300 edgeitems : int, optional
22992301 If number of lines to display is greater than `maxlines`,
23002302 only the first and last `edgeitems` lines are displayed.
2301- Only active if `maxlines` is not None.
2302- Equals to 5 by default.
2303+ Only active if `maxlines` is not -1.
2304+ Defaults to 5.
2305+ light : bool, optional
2306+ Whether or not to hide repeated labels. In other words, only show a label if it is different from the
2307+ previous one. Defaults to False.
23032308 wide : boolean, optional
23042309 Whether or not to write arrays in "wide" format. If True, arrays are exported with the last axis
23052310 represented horizontally. If False, arrays are exported in "narrow" format: one column per axis plus one
@@ -2317,13 +2322,13 @@ def as_table(self, maxlines=None, edgeitems=5, light=False, wide=True, value_nam
23172322 --------
23182323 >>> arr = ndtest((2, 2, 3))
23192324 >>> list(arr.as_table()) # doctest: +NORMALIZE_WHITESPACE
2320- [['a', 'b\\ \\ c', 'c0', 'c1', 'c2'],
2325+ [['a', 'b\\c', 'c0', 'c1', 'c2'],
23212326 ['a0', 'b0', 0, 1, 2],
23222327 ['a0', 'b1', 3, 4, 5],
23232328 ['a1', 'b0', 6, 7, 8],
23242329 ['a1', 'b1', 9, 10, 11]]
23252330 >>> list(arr.as_table(light=True)) # doctest: +NORMALIZE_WHITESPACE
2326- [['a', 'b\\ \\ c', 'c0', 'c1', 'c2'],
2331+ [['a', 'b\\c', 'c0', 'c1', 'c2'],
23272332 ['a0', 'b0', 0, 1, 2],
23282333 ['', 'b1', 3, 4, 5],
23292334 ['a1', 'b0', 6, 7, 8],
@@ -2379,7 +2384,7 @@ def as_table(self, maxlines=None, edgeitems=5, light=False, wide=True, value_nam
23792384 other_colnames = self .axes [- 1 ].labels .tolist () if wide else [value_name ]
23802385 yield axes_names + other_colnames
23812386 # summary if needed
2382- if maxlines is not None and height > maxlines :
2387+ if maxlines >= 0 and height > maxlines :
23832388 # replace middle lines of the table by '...'.
23842389 # We show only the first and last edgeitems lines.
23852390 startticks = islice (ticks , edgeitems )
@@ -2398,7 +2403,8 @@ def as_table(self, maxlines=None, edgeitems=5, light=False, wide=True, value_nam
23982403 yield list (tick ) + dataline .tolist ()
23992404
24002405 def dump (self , header = True , wide = True , value_name = 'value' ):
2401- """Dump array as a 2D nested list
2406+ """
2407+ Dump array as a 2D nested list
24022408
24032409 Parameters
24042410 ----------
@@ -2420,7 +2426,7 @@ def dump(self, header=True, wide=True, value_name='value'):
24202426 # flatten all dimensions except the last one
24212427 return self .data .reshape (- 1 , self .shape [- 1 ]).tolist ()
24222428 else :
2423- return list (self .as_table (wide = wide , value_name = value_name ))
2429+ return list (self .as_table (maxlines = - 1 , wide = wide , value_name = value_name ))
24242430
24252431 # XXX: should filter(geo=['W']) return a view by default? (collapse=True)
24262432 # I think it would be dangerous to make it the default
0 commit comments