@@ -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,12 +2437,15 @@ 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 ):
2444
- r"""
2445
+ maxlines = - 1 , edgeitems = 5 , _axes_display_names = False ):
2446
+ r"""dump(self, header=True, wide=True, value_name='value', light=False, axes_names=True, na_repr='as_is',
2447
+ maxlines=-1, edgeitems=5)
2448
+
2445
2449
Dump array as a 2D nested list. This is especially useful when writing to an Excel sheet via open_excel().
2446
2450
2447
2451
Parameters
@@ -2462,7 +2466,7 @@ def dump(self, header=True, wide=True, value_name='value', light=False, axes_nam
2462
2466
Assuming header is True, whether or not to include axes names. If axes_names is 'except_last',
2463
2467
all axes names will be included except the last. Defaults to True.
2464
2468
na_repr : any scalar, optional
2465
- Replace missing values (NaN floats) by this value. Default to 'as_is' (do not do any replacement).
2469
+ Replace missing values (NaN floats) by this value. Defaults to 'as_is' (do not do any replacement).
2466
2470
maxlines : int, optional
2467
2471
Maximum number of lines to show. Defaults to -1 (all lines are shown).
2468
2472
edgeitems : int, optional
@@ -2516,7 +2520,11 @@ def dump(self, header=True, wide=True, value_name='value', light=False, axes_nam
2516
2520
['...', '...', '...', '...'],
2517
2521
['a1', 'b1', 6, 7]]
2518
2522
"""
2519
- display_axes_names = axes_names
2523
+ # _axes_display_names : bool, optional
2524
+ # Whether or not to get axes names using AxisCollection.display_names instead of
2525
+ # AxisCollection.names. Defaults to False.
2526
+
2527
+ dump_axes_names = axes_names
2520
2528
2521
2529
if not header :
2522
2530
# ensure_no_numpy_type is there mostly to avoid problems with xlwings, but I am unsure where that problem
@@ -2540,14 +2548,18 @@ def dump(self, header=True, wide=True, value_name='value', light=False, axes_nam
2540
2548
data = self .data .reshape (height , width )
2541
2549
2542
2550
# get list of names of axes
2543
- axes_names = self .axes .display_names [:]
2551
+ if _axes_display_names :
2552
+ axes_names = self .axes .display_names [:]
2553
+ else :
2554
+ axes_names = [axis_name if axis_name is not None else '' for axis_name in self .axes .names ]
2544
2555
2545
2556
# transforms ['a', 'b', 'c', 'd'] into ['a', 'b', 'c\\d']
2546
2557
if wide and len (axes_names ) > 1 :
2547
- if display_axes_names is True :
2548
- axes_names [- 2 ] = '\\ ' .join (axes_names [- 2 :])
2558
+ if dump_axes_names is True :
2559
+ separator = '\\ ' if axes_names [- 1 ] else ''
2560
+ axes_names [- 2 ] = separator .join (axes_names [- 2 :])
2549
2561
axes_names .pop ()
2550
- elif display_axes_names == 'except_last' :
2562
+ elif dump_axes_names == 'except_last' :
2551
2563
axes_names = axes_names [:- 1 ]
2552
2564
else :
2553
2565
axes_names = ['' ] * (len (axes_names ) - 1 )
0 commit comments