@@ -2415,7 +2415,8 @@ def __str__(self):
2415
2415
elif not len (self ):
2416
2416
return 'Array([])'
2417
2417
else :
2418
- table = self .dump (maxlines = _OPTIONS [DISPLAY_MAXLINES ], edgeitems = _OPTIONS [DISPLAY_EDGEITEMS ])
2418
+ table = self .dump (maxlines = _OPTIONS [DISPLAY_MAXLINES ], edgeitems = _OPTIONS [DISPLAY_EDGEITEMS ],
2419
+ _axes_display_names = True )
2419
2420
return table2str (table , 'nan' , maxwidth = _OPTIONS [DISPLAY_WIDTH ], keepcols = self .ndim - 1 ,
2420
2421
precision = _OPTIONS [DISPLAY_PRECISION ])
2421
2422
__repr__ = __str__
@@ -2436,11 +2437,12 @@ def as_table(self, maxlines=-1, edgeitems=5, light=False, wide=True, value_name=
2436
2437
"""
2437
2438
warnings .warn ("Array.as_table() is deprecated. Please use Array.dump() instead." , FutureWarning ,
2438
2439
stacklevel = 2 )
2439
- return self .dump (maxlines = maxlines , edgeitems = edgeitems , light = light , wide = wide , value_name = value_name )
2440
+ return self .dump (maxlines = maxlines , edgeitems = edgeitems , light = light , wide = wide , value_name = value_name ,
2441
+ _axes_display_names = True )
2440
2442
2441
2443
# XXX: dump as a 2D Array with row & col dims?
2442
2444
def dump (self , header = True , wide = True , value_name = 'value' , light = False , axes_names = True , na_repr = 'as_is' ,
2443
- maxlines = - 1 , edgeitems = 5 ):
2445
+ maxlines = - 1 , edgeitems = 5 , _axes_display_names = False ):
2444
2446
r"""
2445
2447
Dump array as a 2D nested list. This is especially useful when writing to an Excel sheet via open_excel().
2446
2448
@@ -2462,12 +2464,15 @@ def dump(self, header=True, wide=True, value_name='value', light=False, axes_nam
2462
2464
Assuming header is True, whether or not to include axes names. If axes_names is 'except_last',
2463
2465
all axes names will be included except the last. Defaults to True.
2464
2466
na_repr : any scalar, optional
2465
- Replace missing values (NaN floats) by this value. Default to 'as_is' (do not do any replacement).
2467
+ Replace missing values (NaN floats) by this value. Defaults to 'as_is' (do not do any replacement).
2466
2468
maxlines : int, optional
2467
2469
Maximum number of lines to show. Defaults to -1 (all lines are shown).
2468
2470
edgeitems : int, optional
2469
2471
If number of lines to display is greater than `maxlines`, only the first and last `edgeitems` lines are
2470
2472
displayed. Only active if `maxlines` is not -1. Defaults to 5.
2473
+ _axes_display_names : bool, optional
2474
+ Whether or not to get axes names using :py:obj:`~AxisCollection.display_names` instead of
2475
+ :py:obj:`~AxisCollection.names`. Defaults to False.
2471
2476
2472
2477
Returns
2473
2478
-------
@@ -2516,7 +2521,7 @@ def dump(self, header=True, wide=True, value_name='value', light=False, axes_nam
2516
2521
['...', '...', '...', '...'],
2517
2522
['a1', 'b1', 6, 7]]
2518
2523
"""
2519
- display_axes_names = axes_names
2524
+ dump_axes_names = axes_names
2520
2525
2521
2526
if not header :
2522
2527
# ensure_no_numpy_type is there mostly to avoid problems with xlwings, but I am unsure where that problem
@@ -2540,14 +2545,18 @@ def dump(self, header=True, wide=True, value_name='value', light=False, axes_nam
2540
2545
data = self .data .reshape (height , width )
2541
2546
2542
2547
# get list of names of axes
2543
- axes_names = self .axes .display_names [:]
2548
+ if _axes_display_names :
2549
+ axes_names = self .axes .display_names [:]
2550
+ else :
2551
+ axes_names = [axis_name if axis_name is not None else '' for axis_name in self .axes .names ]
2544
2552
2545
2553
# transforms ['a', 'b', 'c', 'd'] into ['a', 'b', 'c\\d']
2546
2554
if wide and len (axes_names ) > 1 :
2547
- if display_axes_names is True :
2548
- axes_names [- 2 ] = '\\ ' .join (axes_names [- 2 :])
2555
+ if dump_axes_names is True :
2556
+ separator = '\\ ' if axes_names [- 2 ] and axes_names [- 1 ] else ''
2557
+ axes_names [- 2 ] = separator .join (axes_names [- 2 :])
2549
2558
axes_names .pop ()
2550
- elif display_axes_names == 'except_last' :
2559
+ elif dump_axes_names == 'except_last' :
2551
2560
axes_names = axes_names [:- 1 ]
2552
2561
else :
2553
2562
axes_names = ['' ] * (len (axes_names ) - 1 )
0 commit comments