Exemplo n.º 1
0
 def test_fromcolumns(self):
     n = 5
     dlist = [
         np.ones(n, dtype=int),
         np.zeros(n, dtype=float),
         0,
     ]
     dt = np.dtype([("a", float), ("b", float), ("c", float)])
     with pytest.raises(ValueError):
         tab = Table(dlist, dtype=dt)
     tab = Table.from_columns(dlist, dtype=dt)
     print(tab.dtype)
     print(tab.shape)
     print(tab)
     assert tab.h5loc == DEFAULT_H5LOC
     assert isinstance(tab, Table)
     tab = Table.from_columns(dlist, dtype=dt, h5loc="/foo")
     print(tab.dtype)
     print(tab.shape)
     print(tab)
     assert tab.h5loc == "/foo"
     assert isinstance(tab, Table)
     bad_dt = [("a", float), ("b", float), ("c", float), ("d", int)]
     with pytest.raises(ValueError):
         tab = Table.from_columns(dlist, dtype=bad_dt)
         print(tab.dtype)
         print(tab.shape)
         print(tab)
Exemplo n.º 2
0
 def test_fromcolumns(self):
     n = 5
     dlist = [
         np.ones(n, dtype=int),
         np.zeros(n, dtype=float),
         0,
     ]
     dt = np.dtype([('a', float), ('b', float), ('c', float)])
     with pytest.raises(ValueError):
         tab = Table(dlist, dtype=dt)
     tab = Table.from_columns(dlist, dtype=dt)
     print(tab.dtype)
     print(tab.shape)
     print(tab)
     assert tab.h5loc == DEFAULT_H5LOC
     assert isinstance(tab, Table)
     tab = Table.from_columns(dlist, dtype=dt, h5loc='/foo')
     print(tab.dtype)
     print(tab.shape)
     print(tab)
     assert tab.h5loc == '/foo'
     assert isinstance(tab, Table)
     bad_dt = [('a', float), ('b', float), ('c', float), ('d', int)]
     with pytest.raises(ValueError):
         tab = Table.from_columns(dlist, dtype=bad_dt)
         print(tab.dtype)
         print(tab.shape)
         print(tab)
Exemplo n.º 3
0
 def test_add_tables_with_same_colnames_but_different_dtype_order(self):
     cols1 = ("b", "a")
     tab1 = Table.from_columns([[100, 200], [1, 2]], colnames=cols1)
     self.assertTupleEqual(cols1, tab1.dtype.names)
     cols2 = ("a", "b")
     tab2 = Table.from_columns([[3, 4, 5], [300, 400, 500]], colnames=cols2)
     added_tab = tab1 + tab2
     self.assertListEqual([1, 2, 3, 4, 5], list(added_tab.a))
     self.assertListEqual([100, 200, 300, 400, 500], list(added_tab.b))
     self.assertListEqual(list(added_tab.dtype.names),
                          list(tab1.dtype.names))
Exemplo n.º 4
0
 def test_add_tables_with_same_colnames_but_different_dtype_order(self):
     cols1 = ('b', 'a')
     tab1 = Table.from_columns([[100, 200], [1, 2]], colnames=cols1)
     self.assertTupleEqual(cols1, tab1.dtype.names)
     cols2 = ('a', 'b')
     tab2 = Table.from_columns([[3, 4, 5], [300, 400, 500]], colnames=cols2)
     added_tab = tab1 + tab2
     self.assertListEqual([1, 2, 3, 4, 5], list(added_tab.a))
     self.assertListEqual([100, 200, 300, 400, 500], list(added_tab.b))
     self.assertListEqual(
         list(added_tab.dtype.names), list(tab1.dtype.names)
     )
Exemplo n.º 5
0
 def test_from_columns_with_colnames(self):
     t = Table.from_columns([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12],
                             [13, 14, 15], [16, 17, 18], [19, 20, 21]],
                            colnames=['a', 'b', 'c', 'd', 'e', 'f', 'g'])
     print("t.a: {}".format(t.a))
     assert np.allclose([1, 2, 3], t.a)
     print("t.b: {}".format(t.b))
     assert np.allclose([4, 5, 6], t.b)
Exemplo n.º 6
0
 def test_from_columns_with_colnames(self):
     t = Table.from_columns(
         [
             [1, 2, 3],
             [4, 5, 6],
             [7, 8, 9],
             [10, 11, 12],
             [13, 14, 15],
             [16, 17, 18],
             [19, 20, 21],
         ],
         colnames=["a", "b", "c", "d", "e", "f", "g"],
     )
     print("t.a: {}".format(t.a))
     assert np.allclose([1, 2, 3], t.a)
     print("t.b: {}".format(t.b))
     assert np.allclose([4, 5, 6], t.b)
Exemplo n.º 7
0
 def test_from_columns_dim(self):
     t = Table.from_columns([[1, 2, 3], [4, 5.0, 6]], colnames=['a', 'b'])
     assert t.shape == (3, )
Exemplo n.º 8
0
 def test_from_columns_with_mismatching_columns_and_dtypes_raises(self):
     with pytest.raises(ValueError):
         Table.from_columns([[1, 2, 3], [4, 5, 6]],
                            dtype=np.dtype([('a', 'f4')]))
Exemplo n.º 9
0
 def test_from_columns_with_colnames_upcasts(self):
     t = Table.from_columns([[1, 2, 3], [4, 5.0, 6]], colnames=['a', 'b'])
     assert t.dtype == np.dtype([('a', float), ('b', float)])
Exemplo n.º 10
0
 def test_from_columns_dim(self):
     t = Table.from_columns([[1, 2, 3], [4, 5.0, 6]], colnames=["a", "b"])
     assert t.shape == (3, )
Exemplo n.º 11
0
 def test_from_columns_with_mismatching_columns_and_dtypes_raises(self):
     with pytest.raises(ValueError):
         Table.from_columns([[1, 2, 3], [4, 5, 6]],
                            dtype=np.dtype([("a", "f4")]))
Exemplo n.º 12
0
 def test_from_columns_with_colnames_upcasts(self):
     t = Table.from_columns([[1, 2, 3], [4, 5.0, 6]], colnames=["a", "b"])
     assert t.dtype == np.dtype([("a", float), ("b", float)])