Skip to content

Commit 09419de

Browse files
committed
added test for __setitem__ using an ndarray value
1 parent 8fba492 commit 09419de

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

larray/tests/test_la.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,28 @@ def test_setitem_larray(self):
647647
raw[[1, 5, 9]] = raw[[2, 7, 3]] + 27.0
648648
self._assert_equal_raw(la, raw)
649649

650+
def test_setitem_ndarray(self):
651+
"""
652+
tests LArray.__setitem__(key, value) where value is a raw ndarray.
653+
In that case, value.shape is more restricted as we rely on
654+
numpy broadcasting.
655+
"""
656+
# a) value has exactly the same shape as the target slice
657+
la = self.larray.copy()
658+
raw = self.array.copy()
659+
value = raw[[1, 5, 9]] + 25.0
660+
la['1,5,9'] = value
661+
raw[[1, 5, 9]] = value
662+
self._assert_equal_raw(la, raw)
663+
664+
# b) value has the same axes than target but one has length 1
665+
la = self.larray.copy()
666+
raw = self.array.copy()
667+
value = np.sum(raw[[1, 5, 9]], axis=1, keepdims=True)
668+
la['1,5,9'] = value
669+
raw[[1, 5, 9]] = value
670+
self._assert_equal_raw(la, raw)
671+
650672
def test_set(self):
651673
age, geo, sex, lipro = self.larray.axes
652674

0 commit comments

Comments
 (0)