Skip to content

Commit 341ec05

Browse files
committed
FIX: fixed array.sum(incompatible_axis) (fixes #1138) (BUT I am unsure I should fix it, or disallow/warn on array[axis] because it makes aggregates a bit ambiguous (and might break current code)
1 parent 12f444f commit 341ec05

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

larray/core/array.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2937,7 +2937,12 @@ def to_labelgroup(key, stack_depth=1):
29372937

29382938
def standardise_arg(arg, stack_depth=1):
29392939
if self.axes.isaxis(arg):
2940-
return self.axes[arg]
2940+
real_axis = self.axes[arg]
2941+
if (isinstance(arg, Axis) and not isinstance(arg, AxisReference)
2942+
and not arg.equals(real_axis)):
2943+
return arg[:].retarget_to(real_axis)
2944+
else:
2945+
return real_axis
29412946
else:
29422947
return to_labelgroup(arg, stack_depth + 1)
29432948

larray/tests/test_array.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1879,6 +1879,12 @@ def test_sum_full_axes(array):
18791879
# filter on aggregated
18801880
assert aggregated.filter(b=b_group1).shape == (7, 6)
18811881

1882+
# using an Axis object from another array, we must filter the axis
1883+
array = ndtest(3)
1884+
smaller_a_axis = Axis('a=a0,a1')
1885+
res = array.sum(smaller_a_axis)
1886+
assert res == 1
1887+
18821888

18831889
def test_sum_full_axes_with_nan(array):
18841890
array['c0', 'd2', 'b1', 0] = nan

0 commit comments

Comments
 (0)