示例#1
0
 def test_from_dict_with_unordered_columns_wrt_to_dtype_fields(self):
     data = {'b': [1, 2], 'c': [3, 4], 'a': [5, 6]}
     dt = [('a', float), ('b', float), ('c', float)]
     tab = Table.from_dict(data, dtype=dt)
     assert np.allclose([1, 2], tab.b)
     assert np.allclose([3, 4], tab.c)
     assert np.allclose([5, 6], tab.a)
示例#2
0
 def test_from_dict_with_unordered_columns_wrt_to_dtype_fields(self):
     data = {"b": [1, 2], "c": [3, 4], "a": [5, 6]}
     dt = [("a", float), ("b", float), ("c", float)]
     tab = Table.from_dict(data, dtype=dt)
     assert np.allclose([1, 2], tab.b)
     assert np.allclose([3, 4], tab.c)
     assert np.allclose([5, 6], tab.a)
示例#3
0
 def test_from_mixed_dict(self):
     dmap = {
         'a': 1,
         'b': 0.,
         'c': np.zeros(4),
     }
     # tab = Table.from_dict(dmap)
     # self.assertTrue(isinstance(tab, Table))
     # assert tab.h5loc == DEFAULT_H5LOC
     dt = [('a', float), ('b', float), ('c', float)]
     tab = Table.from_dict(dmap, dtype=dt)
     assert tab.h5loc == DEFAULT_H5LOC
     assert isinstance(tab, Table)
     tab = Table.from_dict(dmap, dtype=dt, h5loc='/foo')
     assert tab.h5loc == '/foo'
     assert isinstance(tab, Table)
     bad_dt = [('a', float), ('b', float), ('c', float), ('d', int)]
     with pytest.raises(KeyError):
         tab = Table.from_dict(dmap, dtype=bad_dt)
示例#4
0
 def test_from_mixed_dict(self):
     dmap = {
         "a": 1,
         "b": 0.0,
         "c": np.zeros(4),
     }
     # tab = Table.from_dict(dmap)
     # self.assertTrue(isinstance(tab, Table))
     # assert tab.h5loc == DEFAULT_H5LOC
     dt = [("a", float), ("b", float), ("c", float)]
     tab = Table.from_dict(dmap, dtype=dt)
     assert tab.h5loc == DEFAULT_H5LOC
     assert isinstance(tab, Table)
     tab = Table.from_dict(dmap, dtype=dt, h5loc="/foo")
     assert tab.h5loc == "/foo"
     assert isinstance(tab, Table)
     bad_dt = [("a", float), ("b", float), ("c", float), ("d", int)]
     with pytest.raises(KeyError):
         tab = Table.from_dict(dmap, dtype=bad_dt)
示例#5
0
 def test_from_dict_with_fillna(self):
     data = {'a': [1, 2], 'b': [3, 4]}
     dt = [('a', float), ('b', float), ('c', float)]
     tab = Table.from_dict(data, dtype=dt, fillna=True)
     assert np.isnan(tab.c[0])
     assert np.isnan(tab.c[1])
示例#6
0
 def test_from_dict_without_dtype(self):
     data = {'b': [1, 2], 'c': [3, 4], 'a': [5, 6]}
     tab = Table.from_dict(data)
     assert np.allclose([1, 2], tab.b)
     assert np.allclose([3, 4], tab.c)
     assert np.allclose([5, 6], tab.a)
示例#7
0
 def test_from_dict_with_fillna(self):
     data = {"a": [1, 2], "b": [3, 4]}
     dt = [("a", float), ("b", float), ("c", float)]
     tab = Table.from_dict(data, dtype=dt, fillna=True)
     assert np.isnan(tab.c[0])
     assert np.isnan(tab.c[1])
示例#8
0
 def test_from_dict_without_dtype(self):
     data = {"b": [1, 2], "c": [3, 4], "a": [5, 6]}
     tab = Table.from_dict(data)
     assert np.allclose([1, 2], tab.b)
     assert np.allclose([3, 4], tab.c)
     assert np.allclose([5, 6], tab.a)