Skip to content

Commit ee59645

Browse files
committed
fix #807 : fixed binary operations between a session and an array objects
1 parent 03dda17 commit ee59645

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

doc/source/changes/version_0_32.rst.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ Miscellaneous improvements
5555
Fixes
5656
^^^^^
5757

58-
* fixed something (closes :issue:`1`).
58+
* fixed binary operations between a session and an array object (closes :issue:`807`).

larray/core/session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ def _binop(opname, arrays_only=True):
935935
def opmethod(self, other):
936936
self_keys = set(self.keys())
937937
all_keys = list(self.keys())
938-
if hasattr(other, 'keys'):
938+
if not isinstance(other, LArray) and hasattr(other, 'keys'):
939939
all_keys += [n for n in other.keys() if n not in self_keys]
940940
with np.errstate(call=_session_float_error_handler):
941941
res = []

larray/tests/test_session.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import pytest
99

1010
from larray.tests.common import assert_array_nan_equal, inputpath, tmp_path, meta, needs_xlwings
11-
from larray import (Session, Axis, LArray, Group, isnan, zeros_like, ndtest, ones_like,
11+
from larray import (Session, Axis, LArray, Group, isnan, zeros_like, ndtest, ones_like, ones, full,
1212
local_arrays, global_arrays, arrays)
1313
from larray.util.misc import pickle
1414

@@ -456,6 +456,18 @@ def test_sub(session):
456456
assert diff.a01 is a01
457457
assert diff.c is c
458458

459+
# session - array
460+
axes = [a, b]
461+
sess = Session([('a', a), ('a01', a01), ('c', c), ('e', ndtest(axes)),
462+
('f', full(axes, fill_value=3)), ('g', ndtest('c=c0..c2'))])
463+
diff = sess - ones(axes)
464+
assert_array_nan_equal(diff['e'], sess['e'] - ones(axes))
465+
assert_array_nan_equal(diff['f'], sess['f'] - ones(axes))
466+
assert_array_nan_equal(diff['g'], sess['g'] - ones(axes))
467+
assert diff.a is a
468+
assert diff.a01 is a01
469+
assert diff.c is c
470+
459471

460472
def test_rsub(session):
461473
sess = session

0 commit comments

Comments
 (0)