Skip to content

Commit 65a34e0

Browse files
committed
added boolean argument export_to_excel to LArray.dump() method. Defaults to True.
1 parent ec9d3c4 commit 65a34e0

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

larray/core/array.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2406,7 +2406,7 @@ def as_table(self, maxlines=None, edgeitems=5, light=False, wide=True, value_nam
24062406
# returns next line (labels of N-1 first axes + data)
24072407
yield list(tick) + dataline.tolist()
24082408

2409-
def dump(self, header=True, wide=True, value_name='value'):
2409+
def dump(self, header=True, wide=True, value_name='value', export_to_excel=True):
24102410
"""Dump array as a 2D nested list
24112411
24122412
Parameters
@@ -2420,16 +2420,23 @@ def dump(self, header=True, wide=True, value_name='value'):
24202420
value_name : str, optional
24212421
Name of the column containing the values (last column) when `wide=False` (see above).
24222422
Not used if header=False. Defaults to 'value'.
2423+
export_to_excel: boolean, optional
2424+
Whether or not to prepare special values (like NaNs) before data is dumped to an Excel sheet.
2425+
Defaults to True.
24232426
24242427
Returns
24252428
-------
24262429
2D nested list
24272430
"""
24282431
if not header:
24292432
# flatten all dimensions except the last one
2430-
return self.data.reshape(-1, self.shape[-1]).tolist()
2433+
res = self.data.reshape(-1, self.shape[-1]).tolist()
24312434
else:
2432-
return list(self.as_table(wide=wide, value_name=value_name))
2435+
res = list(self.as_table(wide=wide, value_name=value_name))
2436+
if export_to_excel:
2437+
from xlwings import xlplatform
2438+
res = [[xlplatform.prepare_xl_data_element(x) for x in row] for row in res]
2439+
return res
24332440

24342441
# XXX: should filter(geo=['W']) return a view by default? (collapse=True)
24352442
# I think it would be dangerous to make it the default

0 commit comments

Comments
 (0)