@@ -2415,7 +2415,8 @@ def __str__(self):
24152415 elif not len (self ):
24162416 return 'Array([])'
24172417 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 )
24192420 return table2str (table , 'nan' , maxwidth = _OPTIONS [DISPLAY_WIDTH ], keepcols = self .ndim - 1 ,
24202421 precision = _OPTIONS [DISPLAY_PRECISION ])
24212422 __repr__ = __str__
@@ -2436,12 +2437,15 @@ def as_table(self, maxlines=-1, edgeitems=5, light=False, wide=True, value_name=
24362437 """
24372438 warnings .warn ("Array.as_table() is deprecated. Please use Array.dump() instead." , FutureWarning ,
24382439 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 )
24402442
24412443 # XXX: dump as a 2D Array with row & col dims?
24422444 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+
24452449 Dump array as a 2D nested list. This is especially useful when writing to an Excel sheet via open_excel().
24462450
24472451 Parameters
@@ -2462,7 +2466,7 @@ def dump(self, header=True, wide=True, value_name='value', light=False, axes_nam
24622466 Assuming header is True, whether or not to include axes names. If axes_names is 'except_last',
24632467 all axes names will be included except the last. Defaults to True.
24642468 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).
24662470 maxlines : int, optional
24672471 Maximum number of lines to show. Defaults to -1 (all lines are shown).
24682472 edgeitems : int, optional
@@ -2516,7 +2520,11 @@ def dump(self, header=True, wide=True, value_name='value', light=False, axes_nam
25162520 ['...', '...', '...', '...'],
25172521 ['a1', 'b1', 6, 7]]
25182522 """
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
25202528
25212529 if not header :
25222530 # 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
25402548 data = self .data .reshape (height , width )
25412549
25422550 # 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 ]
25442555
25452556 # transforms ['a', 'b', 'c', 'd'] into ['a', 'b', 'c\\d']
25462557 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 :])
25492561 axes_names .pop ()
2550- elif display_axes_names == 'except_last' :
2562+ elif dump_axes_names == 'except_last' :
25512563 axes_names = axes_names [:- 1 ]
25522564 else :
25532565 axes_names = ['' ] * (len (axes_names ) - 1 )
0 commit comments