Skip to content

Commit 87e06c1

Browse files
committed
>> (820) : modified Array.dump() method so as to dump array with axes.names[-2] = anonymous_axis and axes.names[-1] = axis_name as '\<axis_with_name>' instead of '<axis_with_name>'
1 parent f08da85 commit 87e06c1

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

larray/core/array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2556,7 +2556,7 @@ def dump(self, header=True, wide=True, value_name='value', light=False, axes_nam
25562556
# transforms ['a', 'b', 'c', 'd'] into ['a', 'b', 'c\\d']
25572557
if wide and len(axes_names) > 1:
25582558
if dump_axes_names is True:
2559-
separator = '\\' if axes_names[-2] and axes_names[-1] else ''
2559+
separator = '\\' if axes_names[-1] else ''
25602560
axes_names[-2] = separator.join(axes_names[-2:])
25612561
axes_names.pop()
25622562
elif dump_axes_names == 'except_last':

larray/inout/pandas.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ def from_frame(df, sort_rows=False, sort_columns=False, parse_header=False, unfo
226226
if unfold_last_axis_name:
227227
if isinstance(axes_names[-1], basestring) and '\\' in axes_names[-1]:
228228
last_axes = [name.strip() for name in axes_names[-1].split('\\')]
229+
last_axes = [name if name else None for name in last_axes]
229230
axes_names = axes_names[:-1] + last_axes
230231
else:
231232
axes_names += [None]
@@ -327,8 +328,13 @@ def df_asarray(df, sort_rows=False, sort_columns=False, raw=False, parse_header=
327328
raise ValueError('sort_rows=True is not valid for 1D arrays. Please use sort_columns instead.')
328329
res = from_series(series, sort_rows=sort_columns)
329330
else:
330-
axes_names = [decode(name, 'utf8') if isinstance(name, basestring) else name
331-
for name in df.index.names]
331+
def parse_axis_name(name):
332+
if isinstance(name, basestring):
333+
name = decode(name, 'utf8')
334+
if not name:
335+
name = None
336+
return name
337+
axes_names = [parse_axis_name(name) for name in df.index.names]
332338
unfold_last_axis_name = isinstance(axes_names[-1], basestring) and '\\' in axes_names[-1]
333339
res = from_frame(df, sort_rows=sort_rows, sort_columns=sort_columns, parse_header=parse_header,
334340
unfold_last_axis_name=unfold_last_axis_name, cartesian_prod=cartesian_prod, **kwargs)

larray/tests/test_array.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4137,7 +4137,7 @@ def test_dump():
41374137
# array with an anonymous axis and a wildcard axis
41384138
arr = ndtest((Axis('a0,a1'), Axis(2, 'b')))
41394139
res = arr.dump()
4140-
assert res == [['b', 0, 1],
4140+
assert res == [['\\b', 0, 1],
41414141
['a0', 0, 1],
41424142
['a1', 2, 3]]
41434143
res = arr.dump(_axes_display_names=True)
@@ -4304,7 +4304,7 @@ def test_open_excel(tmpdir):
43044304
assert_array_equal(res, a3.data.reshape((6, 4)))
43054305

43064306
# 4) Blank cells
4307-
# ========================
4307+
# ==============
43084308
# Excel sheet with blank cells on right/bottom border of the array to read
43094309
fpath = inputpath('test_blank_cells.xlsx')
43104310
with open_excel(fpath) as wb:
@@ -4320,7 +4320,16 @@ def test_open_excel(tmpdir):
43204320
assert_array_equal(bad3, good2)
43214321
assert_array_equal(bad4, good2)
43224322

4323-
# 5) crash test
4323+
# 5) anonymous and wilcard axes
4324+
# =============================
4325+
arr = ndtest((Axis('a0,a1'), Axis(2, 'b')))
4326+
fpath = tmp_path(tmpdir, 'anonymous_and_wildcard_axes.xlsx')
4327+
with open_excel(fpath, overwrite_file=True) as wb:
4328+
wb[0] = arr.dump()
4329+
res = wb[0].load()
4330+
assert arr.equals(res)
4331+
4332+
# 6) crash test
43244333
# =============
43254334
arr = ndtest((2, 2))
43264335
fpath = tmp_path(tmpdir, 'temporary_test_file.xlsx')

0 commit comments

Comments
 (0)