def test_datalist(): "Test Datalist class" dl = Datalist(range(10)) # indexing eq_(dl[3], 3) x = dl[:3] assert_is_instance(x, Datalist) assert_array_equal(x, range(3)) assert_array_equal(dl[8:], range(8, 10)) x = dl[np.arange(10) < 3] assert_is_instance(x, Datalist) assert_array_equal(x, range(3)) assert_array_equal(dl[np.arange(3)], range(3)) # __add__ x = dl + range(10, 12) assert_is_instance(x, Datalist) assert_array_equal(x, range(12)) # aggregate x = dl.aggregate(Factor('ab', repeat=5)) assert_is_instance(x, Datalist) assert_array_equal(x, [2.0, 7.0]) # repr dl = Datalist([['a', 'b'], [], ['a']]) eq_(str(dl), "[['a', 'b'], [], ['a']]") dl = Datalist([['a', 'b'], [], ['a']], fmt='strlist') eq_(str(dl), '[[a, b], [], [a]]') eq_(str(dl[:2]), '[[a, b], []]') # eq a = Datalist([[], [1], [], [1]]) b = Datalist([[], [], [2], [1]]) assert_array_equal(a == b, [True, False, False, True]) assert_array_equal(a != b, [False, True, True, False]) # deepcopy ac = deepcopy(a) ok_(ac is not a) assert_array_equal(ac, a) ac[0].append(1) assert_array_equal(ac == a, [False, True, True, True]) # __setitem__ ac[:2] = (1, 2) assert_array_equal(ac == [1, 2, [], [1]], True) ac[np.arange(2, 4)] = [3, 4] assert_array_equal(ac == range(1, 5), True) assert_raises(ValueError, ac.__setitem__, np.arange(2), np.arange(3)) # update a._update_listlist(b) assert_array_equal(a, [[], [1], [2], [1]])
def test_datalist(): "Test Datalist class" dl = Datalist(range(10)) # indexing eq_(dl[3], 3) x = dl[:3] assert_is_instance(x, Datalist) eq_(x, range(3)) eq_(dl[8:], range(8, 10)) x = dl[np.arange(10) < 3] assert_is_instance(x, Datalist) eq_(x, range(3)) eq_(dl[np.arange(3)], range(3)) # __add__ x = dl + range(10, 12) assert_is_instance(x, Datalist) eq_(x, range(12)) # aggregate x = dl.aggregate(Factor('ab', repeat=5)) assert_is_instance(x, Datalist) eq_(x, [2.0, 7.0])
def test_datalist(): "Test Datalist class" dl = Datalist(list(range(10))) # indexing eq_(dl[3], 3) x = dl[:3] assert_is_instance(x, Datalist) assert_array_equal(x, list(range(3))) assert_array_equal(dl[8:], list(range(8, 10))) x = dl[np.arange(10) < 3] assert_is_instance(x, Datalist) assert_array_equal(x, list(range(3))) assert_array_equal(dl[np.arange(3)], list(range(3))) # __add__ x = dl + list(range(10, 12)) assert_is_instance(x, Datalist) assert_array_equal(x, list(range(12))) # aggregate x = dl.aggregate(Factor('ab', repeat=5)) assert_is_instance(x, Datalist) assert_array_equal(x, [2.0, 7.0]) # repr dl = Datalist([['a', 'b'], [], ['a']]) eq_(str(dl), "[['a', 'b'], [], ['a']]") dl = Datalist([['a', 'b'], [], ['a']], fmt='strlist') eq_(str(dl), '[[a, b], [], [a]]') eq_(str(dl[:2]), '[[a, b], []]') # eq a = Datalist([[], [1], [], [1]]) b = Datalist([[], [], [2], [1]]) assert_array_equal(a == b, [True, False, False, True]) assert_array_equal(a != b, [False, True, True, False]) # deepcopy ac = deepcopy(a) ok_(ac is not a) assert_array_equal(ac, a) ac[0].append(1) assert_array_equal(ac == a, [False, True, True, True]) # __setitem__ ac[:2] = (1, 2) assert_array_equal(ac == [1, 2, [], [1]], True) ac[np.arange(2, 4)] = [3, 4] assert_array_equal(ac == list(range(1, 5)), True) assert_raises(ValueError, ac.__setitem__, np.arange(2), np.arange(3)) # update a._update_listlist(b) assert_array_equal(a, [[], [1], [2], [1]])