Example #1
0
 def test_node_discover(self, dt_tb):
     root = PyTables(dt_tb, '/')
     result = discover(root)
     expected = ds.dshape("""{dt: 5 * {id: int64,
                                       name: string[7, "A"],
                                       amount: float64,
                                       date: float64}}""")
     assert result == expected.measure
     root._v_file.close()
Example #2
0
 def test_table_into_ndarray(self, dt_tb):
     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()
Example #3
0
 def test_ndarray_into_table(self, dt_tb):
     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()
Example #4
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, )
Example #5
0
 def test_write_no_dshape(self, tbfile):
     with pytest.raises(ValueError):
         PyTables(path=tbfile, datapath='/write_this')
Example #6
0
 def test_read(self, tbfile):
     t = PyTables(path=tbfile, datapath='/title')
     shape = t.shape
     t._v_file.close()
     assert shape == (5, )
Example #7
0
 def test_datetime_discovery(self, dt_tb):
     t = PyTables(dt_tb, '/dt')
     lhs, rhs = map(discover, (t, dt_data))
     t._v_file.close()
     assert lhs == rhs