8000 FIX: Array.dump() axes_names argument for 1D arrays (closes #1094) · larray-project/larray@833e6b2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 833e6b2

Browse files
committed
FIX: Array.dump() axes_names argument for 1D arrays (closes #1094)
1 parent 17e6423 commit 833e6b2

File tree

3 files changed

+41
-19
lines changed

3 files changed

+41
-19
lines changed

doc/source/changes/version_0_34_3.rst.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,5 @@ Fixes
6565

6666
* fixed :py:obj:`Array.values()` and :py:obj:`Array.items()` on the first axis given by position.
6767
(e.g. `my_array.values(axes=0)`). Closes :issue:`1093`.
68+
69+
* fixed :py:obj:`Array.dump()` ``axes_names`` argument for 1D arrays (closes :issue:`1094`).

larray/core/array.py

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2580,23 +2580,29 @@ def dump(self, header=True, wide=True, value_name='value', light=False, axes_nam
25802580
axes_names = self.axes.names
25812581

25822582
# transforms ['a', 'b', 'c', 'd'] into ['a', 'b', 'c\\d']
2583-
if wide and len(axes_names) > 1:
2584-
if dump_axes_names is True:
2585-
# combine two last names
2586-
last_name = axes_names.pop()
2587-
prev_name = axes_names[-1]
2588-
# do not combine if last_name is None or ''
2589-
if last_name:
2590-
prev_name = prev_name if prev_name is not None else ''
2591-
combined_name = prev_name + '\\' + last_name
2583+
if wide:
2584+
if len(axes_names) == 1:
2585+
# if dump_axes_names is False or 'except_last'
2586+
if dump_axes_names is not True:
2587+
axes_names = []
2588+
# and do nothing when dump_axes_names is True
2589+
elif len(axes_names) > 1:
2590+
if dump_axes_names is True:
2591+
# combine two last names
2592+
last_name = axes_names.pop()
2593+
prev_name = axes_names[-1]
2594+
# do not combine if last_name is None or ''
2595+
if last_name:
2596+
prev_name = prev_name if prev_name is not None else ''
2597+
combined_name = prev_name + '\\' + last_name
2598+
else:
2599+
# whether it is a string or None !
2600+
combined_name = prev_name
2601+
axes_names[-1] = combined_name
2602+
elif dump_axes_names == 'except_last':
2603+
axes_names = axes_names[:-1]
25922604
else:
2593-
# whether it is a string or None !
2594-
combined_name = prev_name
2595-
axes_names[-1] = combined_name
2596-
elif dump_axes_names == 'except_last':
2597-
axes_names = axes_names[:-1]
2598-
else:
2599-
axes_names = [''] * (len(axes_names) - 1)
2605+
axes_names = [''] * (len(axes_names) - 1)
26002606

26012607
axes = self.axes[:-1] if wide else self.axes
26022608

@@ -2605,9 +2611,13 @@ def dump(self, header=True, wide=True, value_name='value', light=False, axes_nam
26052611

26062612
# creates vertical lines (ticks is a list of list)
26072613
if self.ndim == 1 and wide:
2608-
# There is no vertical axis, so the axis name should not have
2609-
# any "tick" below it and we add an empty "tick".
2610-
ticks = [['']]
2614+
if dump_axes_names is True:
2615+
# There is no vertical axis, so the axis name should not have
2616+
# any "tick" below it and we add an empty "tick".
2617+
ticks = [['']]
2618+
else:
2619+
# There is no vertical axis but no axis name either
2620+
ticks = [[]]
26112621
elif light:
26122622
ticks = light_product(*labels)
26132623
else:

larray/tests/test_array.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4772,6 +4772,16 @@ def test_dump():
47724772
['a0', 0, 1],
47734773
['a1', 2, 3]]
47744774

4775+
# axes_names when ndim == 1 (issue #1094)
4776+
arr = ndtest(3)
4777+
res = arr.dump()
4778+
assert res == [['a', 'a0', 'a1', 'a2'], ['', 0, 1, 2]]
4779+
res = arr.dump(axes_names=False)
4780+
# unsure if we should produce [['a0', 'a1', 'a2'], [0, 1, 2]] instead
4781+
assert res == [['a0', 'a1', 'a2'], [0, 1, 2]]
4782+
res = arr.dump(axes_names='except_last')
4783+
assert res == [['a0', 'a1', 'a2'], [0, 1, 2]]
4784+
47754785

47764786
@needs_xlwings
47774787
def test_open_excel(tmp_path):

0 commit comments

Comments
 (0)
0