Skip to content

Commit

Permalink
Uncomment and add to test for assigning to tuples.
Browse files Browse the repository at this point in the history
  • Loading branch information
insertinterestingnamehere committed Jun 9, 2016
1 parent 78c3c72 commit 9acc477
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions dynd/nd/test/test_array_setitem.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
import sys
import unittest
from collections import OrderedDict as odict
from collections import OrderedDict as odict, namedtuple as ntuple
from dynd import nd, ndt

@unittest.skip('Test disabled since callables were reworked')
class TestArraySetItem(unittest.TestCase):

def test_strided_dim(self):
a = nd.empty(100, ndt.int32)
a[...] = nd.range(100)
a[0] = 1000
self.assertEqual(nd.as_py(a[0]), 1000)
a[1:8:3] = 120
self.assertEqual(nd.as_py(a[:11]),
[1000, 120, 2, 3, 120, 5, 6, 120, 8, 9, 10])
a[5:2:-1] = [-10, -20, -30]
self.assertEqual(nd.as_py(a[:11]),
[1000, 120, 2, -30, -20, -10, 6, 120, 8, 9, 10])
a[1] = False
self.assertEqual(nd.as_py(a[1]), 0)
a[2] = True
self.assertEqual(nd.as_py(a[2]), 1)
a[3] = -10.0
self.assertEqual(nd.as_py(a[3]), -10)
# Next line causes a crash.
#a[1:8:3] = 120
#self.assertEqual(nd.as_py(a[:11]),
# [1000, 120, 2, 3, 120, 5, 6, 120, 8, 9, 10])
#a[5:2:-1] = [-10, -20, -30]
#self.assertEqual(nd.as_py(a[:11]),
# [1000, 120, 2, -30, -20, -10, 6, 120, 8, 9, 10])
#a[1] = False
#self.assertEqual(nd.as_py(a[1]), 0)
#a[2] = True
#self.assertEqual(nd.as_py(a[2]), 1)
#a[3] = -10.0
#self.assertEqual(nd.as_py(a[3]), -10)

# Should the following even be supported?
# a[4] = 101.0 + 0j
# self.assertEqual(nd.as_py(a[4]), 101)

# Todo: Add to this test when structs can assign to named tuples.
def test_assign_to_struct(self):
value = [(8, u'world', 4.5), (16, u'!', 8.75)]
# Assign list of tuples
Expand All @@ -44,7 +43,13 @@ def test_assign_to_struct(self):
self.assertEqual(nd.as_py(a), out_val)
# Assign a list of OrderedDicts
a = nd.empty('2 * { i : int32, msg : string, price : float64 }')
a[:] = odict([zip(keys, vals) for vals in value])
a[:] = [odict(zip(keys, vals)) for vals in value]
self.assertEqual(nd.as_py(a), out_val)
# Assign a list of namedtuples
named_class = ntuple('named_class', ['i', 'msg', 'price'])
nt_vals = [named_class(*item) for item in value]
a = nd.empty('2 * { i : int32, msg : string, price : float64 }')
a[:] = nt_vals
self.assertEqual(nd.as_py(a), out_val)

if __name__ == '__main__':
Expand Down

0 comments on commit 9acc477

Please sign in to comment.