Пример #1
0
 def test_table_into_ndarray(self, dt_tb, dt_data):
     t = PyTables(dt_tb, '/dt')
     res = into(np.ndarray, t)
     try:
         for k in res.dtype.fields:
             lhs, rhs = res[k], dt_data[k]
             if (issubclass(np.datetime64, lhs.dtype.type) and
                 issubclass(np.datetime64, rhs.dtype.type)):
                 lhs, rhs = lhs.astype('M8[us]'), rhs.astype('M8[us]')
             assert np.array_equal(lhs, rhs)
     finally:
         t._v_file.close()
Пример #2
0
 def test_ndarray_into_table(self, dt_tb, dt_data):
     dtype = ds.from_numpy(dt_data.shape, dt_data.dtype)
     t = PyTables(dt_tb, '/out', dtype)
     try:
         res = into(np.ndarray, into(t, dt_data, filename=dt_tb, datapath='/out'))
         for k in res.dtype.fields:
             lhs, rhs = res[k], dt_data[k]
             if (issubclass(np.datetime64, lhs.dtype.type) and
                 issubclass(np.datetime64, rhs.dtype.type)):
                 lhs, rhs = lhs.astype('M8[us]'), rhs.astype('M8[us]')
             assert np.array_equal(lhs, rhs)
     finally:
         t._v_file.close()
Пример #3
0
    def test_write_with_dshape(self, tbfile):
        f = tb.open_file(tbfile, mode='a')
        try:
            assert '/write_this' not in f
        finally:
            f.close()
            del f

        # create our table
        dshape = '{id: int, name: string[7, "ascii"], amount: float32}'
        t = PyTables(path=tbfile, datapath='/write_this', dshape=dshape)
        shape = t.shape
        filename = t._v_file.filename
        t._v_file.close()

        assert filename == tbfile
        assert shape == (0,)
Пример #4
0
 def test_write_with_bad_dshape(self, tbfile):
     dshape = '{id: int, name: string, amount: float32}'
     PyTables(path=tbfile, datapath='/write_this', dshape=dshape)
Пример #5
0
 def test_write_no_dshape(self, tbfile):
     with pytest.raises(ValueError):
         PyTables(path=tbfile, datapath='/write_this')
Пример #6
0
 def test_read(self, tbfile):
     t = PyTables(path=tbfile, datapath='/title')
     shape = t.shape
     t._v_file.close()
     assert shape == (5,)
Пример #7
0
 def test_datetime_discovery(self, dt_tb, dt_data):
     t = PyTables(dt_tb, '/dt')
     lhs, rhs = map(discover, (t, dt_data))
     t._v_file.close()
     assert lhs == rhs