65
65
from larray .util .misc import (table2str , size2str , basestring , izip , rproduct , ReprString , duplicates ,
66
66
float_error_handler_factory , _isnoneslice , light_product , unique_list , common_type ,
67
67
renamed_to , deprecate_kwarg , LHDFStore , lazy_attribute )
68
+ from larray .util .options import _OPTIONS , DISPLAY_MAXLINES , DISPLAY_EDGEITEMS , DISPLAY_WIDTH , DISPLAY_PRECISION
68
69
69
70
70
71
def all (values , axis = None ):
@@ -2277,8 +2278,9 @@ def __str__(self):
2277
2278
elif not len (self ):
2278
2279
return 'LArray([])'
2279
2280
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 ])
2282
2284
__repr__ = __str__
2283
2285
2284
2286
def __iter__ (self ):
@@ -2287,19 +2289,22 @@ def __iter__(self):
2287
2289
def __contains__ (self , key ):
2288
2290
return any (key in axis for axis in self .axes )
2289
2291
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 """
2292
2294
Generator. Returns next line of the table representing an array.
2293
2295
2294
2296
Parameters
2295
2297
----------
2296
2298
maxlines : int, optional
2297
- Maximum number of lines to show.
2299
+ Maximum number of lines to show. Defaults to -1 (all lines are shown).
2298
2300
edgeitems : int, optional
2299
2301
If number of lines to display is greater than `maxlines`,
2300
2302
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.
2303
2308
wide : boolean, optional
2304
2309
Whether or not to write arrays in "wide" format. If True, arrays are exported with the last axis
2305
2310
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
2317
2322
--------
2318
2323
>>> arr = ndtest((2, 2, 3))
2319
2324
>>> list(arr.as_table()) # doctest: +NORMALIZE_WHITESPACE
2320
- [['a', 'b\\ \\ c', 'c0', 'c1', 'c2'],
2325
+ [['a', 'b\\c', 'c0', 'c1', 'c2'],
2321
2326
['a0', 'b0', 0, 1, 2],
2322
2327
['a0', 'b1', 3, 4, 5],
2323
2328
['a1', 'b0', 6, 7, 8],
2324
2329
['a1', 'b1', 9, 10, 11]]
2325
2330
>>> list(arr.as_table(light=True)) # doctest: +NORMALIZE_WHITESPACE
2326
- [['a', 'b\\ \\ c', 'c0', 'c1', 'c2'],
2331
+ [['a', 'b\\c', 'c0', 'c1', 'c2'],
2327
2332
['a0', 'b0', 0, 1, 2],
2328
2333
['', 'b1', 3, 4, 5],
2329
2334
['a1', 'b0', 6, 7, 8],
@@ -2379,7 +2384,7 @@ def as_table(self, maxlines=None, edgeitems=5, light=False, wide=True, value_nam
2379
2384
other_colnames = self .axes [- 1 ].labels .tolist () if wide else [value_name ]
2380
2385
yield axes_names + other_colnames
2381
2386
# summary if needed
2382
- if maxlines is not None and height > maxlines :
2387
+ if maxlines >= 0 and height > maxlines :
2383
2388
# replace middle lines of the table by '...'.
2384
2389
# We show only the first and last edgeitems lines.
2385
2390
startticks = islice (ticks , edgeitems )
@@ -2398,7 +2403,8 @@ def as_table(self, maxlines=None, edgeitems=5, light=False, wide=True, value_nam
2398
2403
yield list (tick ) + dataline .tolist ()
2399
2404
2400
2405
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
2402
2408
2403
2409
Parameters
2404
2410
----------
@@ -2420,7 +2426,7 @@ def dump(self, header=True, wide=True, value_name='value'):
2420
2426
# flatten all dimensions except the last one
2421
2427
return self .data .reshape (- 1 , self .shape [- 1 ]).tolist ()
2422
2428
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 ))
2424
2430
2425
2431
# XXX: should filter(geo=['W']) return a view by default? (collapse=True)
2426
2432
# I think it would be dangerous to make it the default
0 commit comments