Exemplo n.º 1
0
 def test03_read_float64(self):
     dtype = "float64"
     ds = getattr(self.fileh.root, dtype)
     self.assertFalse(isinstance(ds, UnImplemented))
     self.assertEqual(ds.shape, (self.ncols, self.nrows))
     self.assertEqual(ds.dtype, dtype)
     data = ds.read()
     common.allequal(data, self.values)
Exemplo n.º 2
0
 def test01_read_float16(self):
     dtype = "float16"
     if hasattr(numpy, dtype):
         ds = getattr(self.fileh.root, dtype)
         self.assertFalse(isinstance(ds, UnImplemented))
         self.assertEqual(ds.shape, (self.ncols, self.nrows))
         self.assertEqual(ds.dtype, dtype)
         data = ds.read()
         common.allequal(data, self.values)
     else:
         ds = self.assertWarns(UserWarning, getattr, self.fileh.root, dtype)
         self.assertTrue(isinstance(ds, UnImplemented))
Exemplo n.º 3
0
    def test(self):
        self.assertIn('/test_var/structure variable', self.h5file)

        tbl = self.h5file.get_node('/test_var/structure variable')
        self.assertIsInstance(tbl, tb.Table)

        self.assertEqual(tbl.colnames, ['a', 'b', 'c', 'd'])

        self.assertEqual(tbl.coltypes['a'], 'float64')
        self.assertEqual(tbl.coldtypes['a'].shape, ())

        self.assertEqual(tbl.coltypes['b'], 'float64')
        self.assertEqual(tbl.coldtypes['b'].shape, ())

        self.assertEqual(tbl.coltypes['c'], 'float64')
        self.assertEqual(tbl.coldtypes['c'].shape, (2, ))

        self.assertEqual(tbl.coltypes['d'], 'string')
        self.assertEqual(tbl.coldtypes['d'].shape, ())

        for row in tbl.iterrows():
            self.assertEqual(row['a'], 3.0)
            self.assertEqual(row['b'], 4.0)
            self.assertTrue(
                common.allequal(row['c'], np.array([2.0, 3.0],
                                                   dtype="float64")))
            self.assertEqual(row['d'], b"d")

        self.h5file.close()
Exemplo n.º 4
0
    def test08a_modifyingRows(self):
        """Checking modifying just one row at once (using modifyRows)."""

        table = self.fileh.root.table
        # Read a chunk of the table
        chunk = table[3]
        # Modify it somewhat
        chunk.field('y')[:] = -1
        table.modifyRows(6, 7, 1, chunk)
        if self.close:
            self.fileh.close()
            self.fileh = openFile(self.file, "a")
            table = self.fileh.root.table
        # Check that some column has been actually modified
        ycol = zeros((2,2), 'Float64')-1
        data = table.cols.y[6]
        if common.verbose:
            print "Type of read:", type(data)
            print "First 3 elements of read:", data[:3]
            print "Length of the data read:", len(data)
        if common.verbose:
            print "ycol-->", ycol
            print "data-->", data
        # Check that both numarray objects are equal
        assert isinstance(data, NumArray)
        # Check the type
        assert data.type() == ycol.type()
        assert allequal(ycol, data, "numarray")
Exemplo n.º 5
0
    def test07b_modifyingRows(self):
        """Checking modifying several rows at once (using cols accessor)."""

        table = self.fileh.root.table
        # Read a chunk of the table
        chunk = table[0:3]
        # Modify it somewhat
        chunk.field('y')[:] = -1
        table.cols[3:6] = chunk
        if self.close:
            self.fileh.close()
            self.fileh = openFile(self.file, "a")
            table = self.fileh.root.table
        # Check that some column has been actually modified
        ycol = zeros((3,2,2), 'Float64')-1
        data = table.cols.y[3:6]
        if common.verbose:
            print "Type of read:", type(data)
            print "First 3 elements of read:", data[:3]
            print "Length of the data read:", len(data)
        if common.verbose:
            print "ycol-->", ycol
            print "data-->", data
        # Check that both numarray objects are equal
        assert isinstance(data, NumArray)
        # Check the type
        assert data.type() == ycol.type()
        assert allequal(ycol, data, "numarray")
Exemplo n.º 6
0
    def test01a_basicTableRead(self):
        """Checking the return of a numarray in read()."""

        if self.close:
            self.fileh.close()
            self.fileh = openFile(self.file, "a")
        table = self.fileh.root.table
        data = table[:]
        if common.verbose:
            print "Type of read:", type(data)
            print "Formats of the record:", data._formats
            print "First 3 elements of read:", data[:3]
        # Check the type of the recarray
        assert isinstance(data, records.RecArray)
        # Check the value of some columns
        # A flat column
        col = table.cols.x[:3]
        assert isinstance(col, NumArray)
        npcol = zeros((3,2), type="Int32")
        if common.verbose:
            print "Plain column:"
            print "read column-->", col
            print "should look like-->", npcol
        assert allequal(col, npcol, "numarray")
        # A nested column
        col = table.cols.Info[:3]
        assert isinstance(col, records.RecArray)
        npcol = self._infozeros
        if common.verbose:
            print "Nested column:"
            print "read column-->", col
            print "should look like-->", npcol
        assert col.descr == npcol.descr
        assert str(col) == str(npcol)
Exemplo n.º 7
0
 def test03_read_float64(self):
     dtype = "float64"
     ds = getattr(self.h5file.root, dtype)
     self.assertFalse(isinstance(ds, tables.UnImplemented))
     self.assertEqual(ds.shape, (self.nrows, self.ncols))
     self.assertEqual(ds.dtype, dtype)
     self.assertTrue(common.allequal(ds.read(), self.values.astype(dtype)))
Exemplo n.º 8
0
    def test04_read_longdouble(self):
        dtype = "longdouble"
        if hasattr(tables, "Float96Atom") or hasattr(tables, "Float128Atom"):
            ds = getattr(self.h5file.root, dtype)
            self.assertFalse(isinstance(ds, tables.UnImplemented))
            self.assertEqual(ds.shape, (self.nrows, self.ncols))
            self.assertEqual(ds.dtype, dtype)
            self.assertTrue(
                common.allequal(ds.read(), self.values.astype(dtype)))

            if hasattr(tables, "Float96Atom"):
                self.assertEqual(ds.dtype, "float96")
            elif hasattr(tables, "Float128Atom"):
                self.assertEqual(ds.dtype, "float128")
        else:
            # XXX: check
            # the behavior depends on the HDF5 lib configuration
            try:
                with self.assertWarns(UserWarning):
                    ds = getattr(self.h5file.root, dtype)
                self.assertTrue(isinstance(ds, tables.UnImplemented))
            except AssertionError:
                from tables.utilsextension import _broken_hdf5_long_double
                if not _broken_hdf5_long_double():
                    ds = getattr(self.h5file.root, dtype)
                    self.assertEqual(ds.dtype, "float64")
Exemplo n.º 9
0
    def test07a_modifyingRows(self):
        """Checking modifying several rows at once (using modifyRows)."""

        table = self.fileh.root.table
        # Read a chunk of the table
        chunk = table[0:3]
        # Modify it somewhat
        chunk.field('y')[:] = -1
        table.modifyRows(3, 6, 1, rows=chunk)
        if self.close:
            self.fileh.close()
            self.fileh = openFile(self.file, "a")
            table = self.fileh.root.table
        ycol = zeros((3, 2, 2), 'Float64') - 1
        data = table.cols.y[3:6]
        if common.verbose:
            print "Type of read:", type(data)
            print "First 3 elements of read:", data[:3]
            print "Length of the data read:", len(data)
        if common.verbose:
            print "ycol-->", ycol
            print "data-->", data
        # Check that both numarray objects are equal
        self.assertTrue(isinstance(data, NumArray))
        # Check the type
        self.assertEqual(data.type(), ycol.type())
        self.assertTrue(allequal(ycol, data, "numarray"))
Exemplo n.º 10
0
    def test01b_basicTableRead(self):
        """Checking the return of a numarray in read() (strided version)."""

        if self.close:
            self.fileh.close()
            self.fileh = openFile(self.file, "a")
        table = self.fileh.root.table
        data = table[::3]
        if common.verbose:
            print "Type of read:", type(data)
            print "Description of the record:", data.descr
            print "First 3 elements of read:", data[:3]
        # Check that both numarray objects are equal
        self.assertTrue(isinstance(data, records.RecArray))
        # Check the value of some columns
        # A flat column
        col = table.cols.x[:9:3]
        self.assertTrue(isinstance(col, NumArray))
        npcol = zeros((3, 2), dtype="Int32")
        if common.verbose:
            print "Plain column:"
            print "read column-->", col
            print "should look like-->", npcol
        self.assertTrue(allequal(col, npcol, "numarray"))
        # A nested column
        col = table.cols.Info[:9:3]
        self.assertTrue(isinstance(col, records.RecArray))
        npcol = self._infozeros
        if common.verbose:
            print "Nested column:"
            print "read column-->", col
            print "should look like-->", npcol
        self.assertEqual(col.descr, npcol.descr)
        self.assertEqual(str(col), str(npcol))
Exemplo n.º 11
0
    def test05b_modifyingColumns(self):
        """Checking modifying several columns at once."""

        table = self.fileh.root.table
        xcol = ones((3, 2), 'Int32')
        ycol = ones((3, 2, 2), 'Float64')
        zcol = zeros((3, ), 'UInt8')
        table.modifyColumns(3, 6, 1, [xcol, ycol, zcol], ['x', 'y', 'z'])
        if self.close:
            self.fileh.close()
            self.fileh = openFile(self.file, "a")
            table = self.fileh.root.table
        data = table.cols.y[3:6]
        if common.verbose:
            print "Type of read:", type(data)
            print "First 3 elements of read:", data[:3]
            print "Length of the data read:", len(data)
        if common.verbose:
            print "ycol-->", ycol
            print "data-->", data
        # Check that both numarray objects are equal
        self.assertTrue(isinstance(data, NumArray))
        # Check the type
        self.assertEqual(data.type(), ycol.type())
        self.assertTrue(allequal(data, ycol, "numarray"))
Exemplo n.º 12
0
    def test01_readTableChar(self):
        """Checking column conversion into NumPy in read().

        Char flavor

        """

        table = self.h5file.root.table
        table.flavor = "numpy"
        for colname in table.colnames:
            numcol = table.read(field=colname)
            typecol = table.coltypes[colname]
            itemsizecol = table.description._v_dtypes[colname].base.itemsize
            nctypecode = numcol.dtype.char
            if typecol == "string":
                if itemsizecol > 1:
                    orignumcol = np.array(['abcd'] * self.nrows, dtype='S4')
                else:
                    orignumcol = np.array(['a'] * self.nrows, dtype='S1')
                if common.verbose:
                    print("Typecode of NumPy column read:", nctypecode)
                    print("Should look like:", 'c')
                    print("Itemsize of column:", itemsizecol)
                    print("Shape of NumPy column read:", numcol.shape)
                    print("Should look like:", orignumcol.shape)
                    print("First 3 elements of read col:", numcol[:3])
                # Check that both NumPy objects are equal
                self.assertTrue(allequal(numcol, orignumcol, "numpy"))
Exemplo n.º 13
0
    def test07a_modifyingRows(self):
        """Checking modifying several rows at once (using modify_rows)."""

        table = self.h5file.root.table

        # Read a chunk of the table
        chunk = table[0:3]

        # Modify it somewhat
        chunk['y'][:] = -1
        table.modify_rows(3, 6, 1, rows=chunk)
        if self.close:
            self._reopen(mode='a')
            table = self.h5file.root.table
        ycol = np.zeros((3, 2, 2), 'float64') - 1
        data = table.cols.y[3:6]
        if common.verbose:
            print("Type of read:", type(data))
            print("Description of the record:", data.dtype.descr)
            print("First 3 elements of read:", data[:3])
            print("Length of the data read:", len(data))

        # Check that both NumPy objects are equal
        self.assertIsInstance(data, np.ndarray)

        # Check the type
        self.assertEqual(data.dtype.descr, ycol.dtype.descr)
        if common.verbose:
            print("ycol-->", ycol)
            print("data-->", data)
        self.assertTrue(allequal(ycol, data, "numpy"))
Exemplo n.º 14
0
    def WriteRead(self, testArray):
        if common.verbose:
            print('\n', '-=' * 30)
            print("Running test for array with typecode '%s'" %
                  testArray.dtype.char,
                  end=' ')
            print("for class check:", self.title)

        # Create an instance of HDF5 Table
        self.h5fname = tempfile.mktemp(".h5")
        try:
            with tables.open_file(self.h5fname, mode="w") as self.h5file:
                self.root = self.h5file.root

                # Create the array under root and name 'somearray'
                a = testArray
                self.h5file.create_array(self.root, 'somearray', a,
                                         "Some array")

            # Re-open the file in read-only mode
            with tables.open_file(self.h5fname, mode="r") as self.h5file:
                self.root = self.h5file.root

                # Read the saved array
                b = self.root.somearray.read()

                # For cases that read returns a python type instead of a
                # numpy type
                if not hasattr(b, "shape"):
                    b = np.np.array(b, dtype=a.dtype.str)

                # Compare them. They should be equal.
                # if not allequal(a,b, "numpy") and common.verbose:
                if common.verbose:
                    print("Array written:", a)
                    print("Array written shape:", a.shape)
                    print("Array written itemsize:", a.itemsize)
                    print("Array written type:", a.dtype.char)
                    print("Array read:", b)
                    print("Array read shape:", b.shape)
                    print("Array read itemsize:", b.itemsize)
                    print("Array read type:", b.dtype.char)

                type_ = self.root.somearray.atom.type

                # Check strictly the array equality
                self.assertEqual(type(a), type(b))
                self.assertEqual(a.shape, b.shape)
                self.assertEqual(a.shape, self.root.somearray.shape)
                self.assertEqual(a.dtype, b.dtype)
                if a.dtype.char[0] == "S":
                    self.assertEqual(type_, "string")
                else:
                    self.assertEqual(a.dtype.base.name, type_)

                self.assertTrue(allequal(a, b, "numpy"))
        finally:
            # Then, delete the file
            if os.path.exists(self.h5fname):
                os.remove(self.h5fname)
Exemplo n.º 15
0
    def test02_updateAttribute(self):
        """Checking the modification of a numpy attribute."""

        group = self.h5file.root.group
        g_attrs = group._v_attrs
        g_attrs.numpy1 = np.zeros((1, 2), dtype='int16')
        if self.close:
            self._reopen(mode='a')
            group = self.h5file.root.group
            g_attrs = group._v_attrs

        # Update this attribute
        g_attrs.numpy1 = np.ones((1, 2), dtype='int16')

        # Check that we can retrieve a numpy object
        data = g_attrs.numpy1
        npcomp = np.ones((1, 2), dtype='int16')

        # Check that both NumPy objects are equal
        self.assertIsInstance(data, np.ndarray)

        # Check the type
        self.assertEqual(data.dtype.descr, npcomp.dtype.descr)
        if common.verbose:
            print("npcomp-->", npcomp)
            print("data-->", data)
        self.assertTrue(allequal(npcomp, data, "numpy"))
Exemplo n.º 16
0
    def test08b_modifyingRows(self):
        """Checking modifying just one row at once (using cols accessor)."""

        table = self.h5file.root.table

        # Read a chunk of the table
        chunk = table[3:4]

        # Modify it somewhat
        chunk['y'][:] = -1
        table.cols[6] = chunk
        if self.close:
            self._reopen(mode='a')
            table = self.h5file.root.table

        # Check that some column has been actually modified
        ycol = np.zeros((2, 2), 'float64') - 1
        data = table.cols.y[6]
        if common.verbose:
            print("Type of read:", type(data))
            print("Description of the record:", data.dtype.descr)
            print("First 3 elements of read:", data[:3])
            print("Length of the data read:", len(data))

        # Check that both NumPy objects are equal
        self.assertIsInstance(data, np.ndarray)

        # Check the type
        self.assertEqual(data.dtype.descr, ycol.dtype.descr)
        if common.verbose:
            print("ycol-->", ycol)
            print("data-->", data)
        self.assertTrue(allequal(ycol, data, "numpy"))
Exemplo n.º 17
0
    def test08b_modifyingRows(self):
        """Checking modifying just one row at once (using cols accessor)."""

        table = self.fileh.root.table
        # Read a chunk of the table
        chunk = table[3]
        # Modify it somewhat
        chunk['y'][:] = -1
        table.cols[6] = chunk
        if self.close:
            self.fileh.close()
            self.fileh = openFile(self.file, "a")
            table = self.fileh.root.table
        # Check that some column has been actually modified
        ycol = zeros((2, 2), 'Float64') - 1
        data = table.cols.y[6]
        if common.verbose:
            print "Type of read:", type(data)
            print "First 3 elements of read:", data[:3]
            print "Length of the data read:", len(data)
        if common.verbose:
            print "ycol-->", ycol
            print "data-->", data
        # Check that both numarray objects are equal
        self.assertTrue(isinstance(data, NumArray))
        # Check the type
        self.assertEqual(data.type(), ycol.type())
        self.assertTrue(allequal(ycol, data, "numarray"))
Exemplo n.º 18
0
    def test08a_modifyingRows(self):
        """Checking modifying just one row at once (using modifyRows)."""

        table = self.fileh.root.table
        # Read a chunk of the table
        chunk = table[3]
        # Modify it somewhat
        chunk['y'][:] = -1
        table.modifyRows(6, 7, 1, chunk)
        if self.close:
            self.fileh.close()
            self.fileh = openFile(self.file, "a")
            table = self.fileh.root.table
        # Check that some column has been actually modified
        ycol = zeros((2, 2), 'float64') - 1
        data = table.cols.y[6]
        if common.verbose:
            print "Type of read:", type(data)
            print "Description of the record:", data.dtype.descr
            print "First 3 elements of read:", data[:3]
            print "Length of the data read:", len(data)
        # Check that both NumPy objects are equal
        assert isinstance(data, ndarray)
        # Check the type
        assert data.dtype.descr == ycol.dtype.descr
        if common.verbose:
            print "ycol-->", ycol
            print "data-->", data
        assert allequal(ycol, data, "numpy")
Exemplo n.º 19
0
    def _test(self):
        self.assert_("/test_var/structure variable" in self.h5file)

        tbl = self.h5file.getNode("/test_var/structure variable")
        self.assert_(isinstance(tbl, tables.Table))

        self.assertEqual(tbl.colnames, ["a", "b", "c", "d"])

        self.assertEqual(tbl.coltypes["a"], "float64")
        self.assertEqual(tbl.coldtypes["a"].shape, ())

        self.assertEqual(tbl.coltypes["b"], "float64")
        self.assertEqual(tbl.coldtypes["b"].shape, ())

        self.assertEqual(tbl.coltypes["c"], "float64")
        self.assertEqual(tbl.coldtypes["c"].shape, (2,))

        self.assertEqual(tbl.coltypes["d"], "string")
        self.assertEqual(tbl.coldtypes["d"].shape, ())

        for row in tbl.iterrows():
            self.assertEqual(row["a"], 3.0)
            self.assertEqual(row["b"], 4.0)
            self.assert_(allequal(row["c"], numpy.array([2.0, 3.0], dtype="float64")))
            self.assertEqual(row["d"], "d")

        self.h5file.close()
Exemplo n.º 20
0
    def test01_readTableChar(self):
        """Checking column conversion into Numeric in read(). Char flavor"""

        table = self.fileh.root.table
        table.flavor = "numeric"
        for colname in table.colnames:
            numcol = table.read(field=colname)
            typecol = table.coltypes[colname]
            itemsizecol = table.description._v_dtypes[colname].base.itemsize
            nctypecode = numcol.typecode()
            if typecol == "string":
                if itemsizecol > 1:
                    orignumcol = array(['abcd'] * self.nrows, typecode='c')
                else:
                    orignumcol = array(['a'] * self.nrows, typecode='c')
                    orignumcol.shape = (self.nrows, )
                if common.verbose:
                    print "Typecode of Numeric column read:", nctypecode
                    print "Should look like:", 'c'
                    print "Itemsize of column:", itemsizecol
                    print "Shape of Numeric column read:", numcol.shape
                    print "Should look like:", orignumcol.shape
                    print "First 3 elements of read col:", numcol[:3]
                # Check that both Numeric objects are equal
                self.assertTrue(allequal(numcol, orignumcol, "numeric"))
Exemplo n.º 21
0
    def test05b_modifyingColumns(self):
        """Checking modifying several columns at once."""

        table = self.fileh.root.table
        xcol = ones((3, 2), 'Int32')
        ycol = ones((3, 2, 2), 'Float64')
        zcol = zeros((3,), 'UInt8')
        table.modifyColumns(3, 6, 1, [xcol, ycol, zcol], ['x', 'y', 'z'])
        if self.close:
            self.fileh.close()
            self.fileh = openFile(self.file, "a")
            table = self.fileh.root.table
        data = table.cols.y[3:6]
        if common.verbose:
            print "Type of read:", type(data)
            print "First 3 elements of read:", data[:3]
            print "Length of the data read:", len(data)
        if common.verbose:
            print "ycol-->", ycol
            print "data-->", data
        # Check that both numarray objects are equal
        self.assertTrue(isinstance(data, NumArray))
        # Check the type
        self.assertEqual(data.type(), ycol.type())
        self.assertTrue(allequal(data, ycol, "numarray"))
Exemplo n.º 22
0
    def test08b_modifyingRows(self):
        """Checking modifying just one row at once (using cols accessor)."""

        table = self.fileh.root.table
        # Read a chunk of the table
        chunk = table[3]
        # Modify it somewhat
        chunk['y'][:] = -1
        table.cols[6] = chunk
        if self.close:
            self.fileh.close()
            self.fileh = openFile(self.file, "a")
            table = self.fileh.root.table
        # Check that some column has been actually modified
        ycol = zeros((2, 2), 'Float64')-1
        data = table.cols.y[6]
        if common.verbose:
            print "Type of read:", type(data)
            print "First 3 elements of read:", data[:3]
            print "Length of the data read:", len(data)
        if common.verbose:
            print "ycol-->", ycol
            print "data-->", data
        # Check that both numarray objects are equal
        self.assertTrue(isinstance(data, NumArray))
        # Check the type
        self.assertEqual(data.type(), ycol.type())
        self.assertTrue(allequal(ycol, data, "numarray"))
Exemplo n.º 23
0
    def test03b_Compare64EArray(self):
        """Comparing several written and read 64-bit time values in an
        EArray."""

        # Create test EArray with data.
        ea = self.h5file.create_earray('/',
                                       'test',
                                       tb.Time64Atom(),
                                       shape=(0, 2))

        # Size of the test.
        nrows = ea.nrowsinbuf + 34  # Add some more rows than buffer.
        # Only for home checks; the value above should check better
        # the I/O with multiple buffers.
        # nrows = 10

        for i in range(nrows):
            j = i * 2
            ea.append(((j + 0.012, j + 1 + 0.012), ))
        self._reopen()

        # Check the written data.
        arr = self.h5file.root.test.read()
        self.h5file.close()

        orig_val = np.arange(0, nrows * 2, dtype=np.int32) + 0.012
        orig_val.shape = (nrows, 2)
        if common.verbose:
            print("Original values:", orig_val)
            print("Retrieved values:", arr)
        self.assertTrue(common.allequal(arr, orig_val),
                        "Stored and retrieved values do not match.")
Exemplo n.º 24
0
    def test02_readCoordsChar(self):
        """Column conversion into Numeric in readCoords(). Chars"""

        table = self.fileh.root.table
        table.flavor = "numeric"
        coords = (1, 2, 3)
        self.nrows = len(coords)
        for colname in table.colnames:
            numcol = table.readCoordinates(coords, field=colname)
            typecol = table.coltypes[colname]
            itemsizecol = table.description._v_dtypes[colname].base.itemsize
            nctypecode = numcol.typecode()
            if typecol == "string":
                if itemsizecol > 1:
                    orignumcol = array(['abcd']*self.nrows, typecode='c')
                else:
                    orignumcol = array(['a']*self.nrows, typecode='c')
                    orignumcol.shape=(self.nrows,)
                if common.verbose:
                    print "Typecode of Numeric column read:", nctypecode
                    print "Should look like:", 'c'
                    print "Itemsize of column:", itemsizecol
                    print "Shape of Numeric column read:", numcol.shape
                    print "Should look like:", orignumcol.shape
                    print "First 3 elements of read col:", numcol[:3]
                # Check that both Numeric objects are equal
                self.assertTrue(allequal(numcol, orignumcol, "numeric"))
Exemplo n.º 25
0
    def _test(self):
        self.assert_('/test_var/structure variable' in self.h5file)

        tbl = self.h5file.getNode('/test_var/structure variable')
        self.assert_(isinstance(tbl, tables.Table))

        self.assertEqual(tbl.colnames, ['a', 'b', 'c', 'd'])

        self.assertEqual(tbl.coltypes['a'], 'float64')
        self.assertEqual(tbl.coldtypes['a'].shape, ())

        self.assertEqual(tbl.coltypes['b'], 'float64')
        self.assertEqual(tbl.coldtypes['b'].shape, ())

        self.assertEqual(tbl.coltypes['c'], 'float64')
        self.assertEqual(tbl.coldtypes['c'].shape, (2, ))

        self.assertEqual(tbl.coltypes['d'], 'string')
        self.assertEqual(tbl.coldtypes['d'].shape, ())

        for row in tbl.iterrows():
            self.assertEqual(row['a'], 3.0)
            self.assertEqual(row['b'], 4.0)
            self.assert_(
                allequal(row['c'], numpy.array([2.0, 3.0], dtype="float64")))
            self.assertEqual(row['d'], "d")

        self.h5file.close()
Exemplo n.º 26
0
    def test02_readCoordsChar(self):
        """Column conversion into NumPy in readCoords(). Chars"""

        table = self.fileh.root.table
        table.flavor = "numpy"
        coords = (1, 2, 3)
        self.nrows = len(coords)
        for colname in table.colnames:
            numcol = table.readCoordinates(coords, field=colname)
            typecol = table.coltypes[colname]
            itemsizecol = table.description._v_dtypes[colname].base.itemsize
            nctypecode = numcol.dtype.char
            if typecol == "string":
                if itemsizecol > 1:
                    orignumcol = array(['abcd'] * self.nrows, dtype='S4')
                else:
                    orignumcol = array(['a'] * self.nrows, dtype='S1')
                if common.verbose:
                    print "Typecode of NumPy column read:", nctypecode
                    print "Should look like:", 'c'
                    print "Itemsize of column:", itemsizecol
                    print "Shape of NumPy column read:", numcol.shape
                    print "Should look like:", orignumcol.shape
                    print "First 3 elements of read col:", numcol[:3]
                # Check that both NumPy objects are equal
                assert allequal(numcol, orignumcol, "numpy")
Exemplo n.º 27
0
 def test02_read_float32(self):
     dtype = "float32"
     ds = getattr(self.h5file.root, dtype)
     self.assertNotIsInstance(ds, tb.UnImplemented)
     self.assertEqual(ds.shape, (self.nrows, self.ncols))
     self.assertEqual(ds.dtype, dtype)
     self.assertTrue(common.allequal(ds.read(), self.values.astype(dtype)))
Exemplo n.º 28
0
    def test07a_modifyingRows(self):
        """Checking modifying several rows at once (using modifyRows)."""

        table = self.fileh.root.table
        # Read a chunk of the table
        chunk = table[0:3]
        # Modify it somewhat
        chunk.field('y')[:] = -1
        table.modifyRows(3, 6, 1, rows=chunk)
        if self.close:
            self.fileh.close()
            self.fileh = openFile(self.file, "a")
            table = self.fileh.root.table
        ycol = zeros((3, 2, 2), 'Float64')-1
        data = table.cols.y[3:6]
        if common.verbose:
            print "Type of read:", type(data)
            print "First 3 elements of read:", data[:3]
            print "Length of the data read:", len(data)
        if common.verbose:
            print "ycol-->", ycol
            print "data-->", data
        # Check that both numarray objects are equal
        self.assertTrue(isinstance(data, NumArray))
        # Check the type
        self.assertEqual(data.type(), ycol.type())
        self.assertTrue(allequal(ycol, data, "numarray"))
Exemplo n.º 29
0
    def test03b_Compare64EArray(self):
        "Comparing several written and read 64-bit time values in an EArray."

        # Create test EArray with data.
        h5file = tables.openFile(
                self.h5fname, 'w', title = "Test for comparing Time64 E arrays")
        ea = h5file.createEArray(
                '/', 'test', tables.Time64Atom(), shape=(0, 2))

        # Size of the test.
        nrows = ea.nrowsinbuf + 34  # Add some more rows than buffer.
        # Only for home checks; the value above should check better
        # the I/O with multiple buffers.
        ##nrows = 10

        for i in xrange(nrows):
            j = i * 2
            ea.append(((j + 0.012, j + 1 + 0.012),))
        h5file.close()

        # Check the written data.
        h5file = tables.openFile(self.h5fname)
        arr = h5file.root.test.read()
        h5file.close()

        orig_val = numpy.arange(0, nrows*2, dtype=numpy.int32) + 0.012
        orig_val.shape = (nrows, 2)
        if common.verbose:
            print "Original values:", orig_val
            print "Retrieved values:", arr
        self.assertTrue(allequal(arr, orig_val),
                        "Stored and retrieved values do not match.")
Exemplo n.º 30
0
    def test01b_Compare64VLArray(self):
        "Comparing several written and read 64-bit time values in a VLArray."

        # Create test VLArray with data.
        h5file = tables.open_file(self.h5fname, "w", title="Test for comparing Time64 VL arrays")
        vla = h5file.create_vlarray("/", "test", self.myTime64Atom)

        # Size of the test.
        nrows = vla.nrowsinbuf + 34  # Add some more rows than buffer.
        # Only for home checks; the value above should check better
        # the I/O with multiple buffers.
        # nrows = 10

        for i in range(nrows):
            j = i * 2
            vla.append((j + 0.012, j + 1 + 0.012))
        h5file.close()

        # Check the written data.
        h5file = tables.open_file(self.h5fname)
        arr = h5file.root.test.read()
        h5file.close()

        arr = numpy.array(arr)
        orig_val = numpy.arange(0, nrows * 2, dtype=numpy.int32) + 0.012
        orig_val.shape = (nrows, 1, 2)
        if common.verbose:
            print("Original values:", orig_val)
            print("Retrieved values:", arr)
        self.assertTrue(allequal(arr, orig_val), "Stored and retrieved values do not match.")
Exemplo n.º 31
0
    def test01b_basicTableRead(self):
        """Checking the return of a numarray in read() (strided version)."""

        if self.close:
            self.fileh.close()
            self.fileh = openFile(self.file, "a")
        table = self.fileh.root.table
        data = table[::3]
        if common.verbose:
            print "Type of read:", type(data)
            print "Description of the record:", data.descr
            print "First 3 elements of read:", data[:3]
        # Check that both numarray objects are equal
        self.assertTrue(isinstance(data, records.RecArray))
        # Check the value of some columns
        # A flat column
        col = table.cols.x[:9:3]
        self.assertTrue(isinstance(col, NumArray))
        npcol = zeros((3, 2), dtype="Int32")
        if common.verbose:
            print "Plain column:"
            print "read column-->", col
            print "should look like-->", npcol
        self.assertTrue(allequal(col, npcol, "numarray"))
        # A nested column
        col = table.cols.Info[:9:3]
        self.assertTrue(isinstance(col, records.RecArray))
        npcol = self._infozeros
        if common.verbose:
            print "Nested column:"
            print "read column-->", col
            print "should look like-->", npcol
        self.assertEqual(col.descr, npcol.descr)
        self.assertEqual(str(col), str(npcol))
Exemplo n.º 32
0
 def test03_read_float64(self):
     dtype = "float64"
     ds = getattr(self.h5file.root, dtype)
     self.assertFalse(isinstance(ds, tables.UnImplemented))
     self.assertEqual(ds.shape, (self.nrows, self.ncols))
     self.assertEqual(ds.dtype, dtype)
     self.assertTrue(common.allequal(ds.read(), self.values.astype(dtype)))
Exemplo n.º 33
0
    def test07b_modifyingRows(self):
        """Checking modifying several rows at once (using cols accessor)."""

        table = self.fileh.root.table
        # Read a chunk of the table
        chunk = table[0:3]
        # Modify it somewhat
        chunk['y'][:] = -1
        table.cols[3:6] = chunk
        if self.close:
            self.fileh.close()
            self.fileh = openFile(self.file, "a")
            table = self.fileh.root.table
        # Check that some column has been actually modified
        ycol = zeros((3,2,2), 'float64')-1
        data = table.cols.y[3:6]
        if common.verbose:
            print "Type of read:", type(data)
            print "Description of the record:", data.dtype.descr
            print "First 3 elements of read:", data[:3]
            print "Length of the data read:", len(data)
        # Check that both NumPy objects are equal
        assert isinstance(data, ndarray)
        # Check the type
        assert data.dtype.descr == ycol.dtype.descr
        if common.verbose:
            print "ycol-->", ycol
            print "data-->", data
        assert allequal(ycol, data, "numpy")
Exemplo n.º 34
0
    def test04_read_longdouble(self):
        dtype = "longdouble"
        if "Float96Atom" in globals() or "Float128Atom" in globals():
            ds = getattr(self.fileh.root, dtype)
            self.assertFalse(isinstance(ds, UnImplemented))
            self.assertEqual(ds.shape, (self.nrows, self.ncols))
            self.assertEqual(ds.dtype, dtype)
            self.assertTrue(common.allequal(
                ds.read(), self.values.astype(dtype)))

            if "Float96Atom" in globals():
                self.assertEqual(ds.dtype, "float96")
            elif "Float128Atom" in globals():
                self.assertEqual(ds.dtype, "float128")
        else:
            # XXX: check
            # the behavior depends on the HDF5 lib configuration
            try:
                ds = self.assertWarns(UserWarning,
                                      getattr, self.fileh.root, dtype)
                self.assertTrue(isinstance(ds, UnImplemented))
            except AssertionError:
                from tables.utilsextension import _broken_hdf5_long_double
                if not _broken_hdf5_long_double():
                    ds = getattr(self.fileh.root, dtype)
                    self.assertEqual(ds.dtype, "float64")
Exemplo n.º 35
0
    def test01b_basicTableRead(self):
        """Checking the return of a NumPy in read() (strided version)."""

        if self.close:
            self.fileh.close()
            self.fileh = openFile(self.file, "a")
        table = self.fileh.root.table
        data = table[::3]
        if common.verbose:
            print "Type of read:", type(data)
            print "Description of the record:", data.dtype.descr
            print "First 3 elements of read:", data[:3]
        # Check that both NumPy objects are equal
        assert isinstance(data, ndarray)
        # Check the value of some columns
        # A flat column
        col = table.cols.x[:9:3]
        assert isinstance(col, ndarray)
        npcol = zeros((3, 2), dtype="int32")
        assert allequal(col, npcol, "numpy")
        # A nested column
        col = table.cols.Info[:9:3]
        assert isinstance(col, ndarray)
        dtype = [('value', '%sc16' % byteorder), ('y2', '%sf8' % byteorder),
                 ('Info2', [('name', '|S2'),
                            ('value', '%sc16' % byteorder, (2, )),
                            ('y3', '%sf8' % byteorder, (2, ))]),
                 ('name', '|S2'), ('z2', '|u1')]
        npcol = zeros((3, ), dtype=dtype)
        assert col.dtype.descr == npcol.dtype.descr
        if common.verbose:
            print "col-->", col
            print "npcol-->", npcol
        # A copy() is needed in case the buffer can be in different segments
        assert col.copy().data == npcol.data
Exemplo n.º 36
0
    def _test(self):
        self.assertTrue('/test_var/structure variable' in self.h5file)

        tbl = self.h5file.get_node('/test_var/structure variable')
        self.assertTrue(isinstance(tbl, tables.Table))

        self.assertEqual(
            tbl.colnames,
            ['a', 'b', 'c', 'd'])

        self.assertEqual(tbl.coltypes['a'], 'float64')
        self.assertEqual(tbl.coldtypes['a'].shape, ())

        self.assertEqual(tbl.coltypes['b'], 'float64')
        self.assertEqual(tbl.coldtypes['b'].shape, ())

        self.assertEqual(tbl.coltypes['c'], 'float64')
        self.assertEqual(tbl.coldtypes['c'].shape, (2,))

        self.assertEqual(tbl.coltypes['d'], 'string')
        self.assertEqual(tbl.coldtypes['d'].shape, ())

        for row in tbl.iterrows():
            self.assertEqual(row['a'], 3.0)
            self.assertEqual(row['b'], 4.0)
            self.assertTrue(allequal(row['c'], numpy.array([2.0, 3.0],
                                                           dtype="float64")))
            self.assertEqual(row['d'], b"d")

        self.h5file.close()
Exemplo n.º 37
0
    def test03b_Compare64EArray(self):
        "Comparing several written and read 64-bit time values in an EArray."

        # Create test EArray with data.
        h5file = tables.openFile(self.h5fname,
                                 'w',
                                 title="Test for comparing Time64 E arrays")
        ea = h5file.createEArray('/',
                                 'test',
                                 tables.Time64Atom(),
                                 shape=(0, 2))

        # Size of the test.
        nrows = ea.nrowsinbuf + 34  # Add some more rows than buffer.
        # Only for home checks; the value above should check better
        # the I/O with multiple buffers.
        ##nrows = 10

        for i in xrange(nrows):
            j = i * 2
            ea.append(((j + 0.012, j + 1 + 0.012), ))
        h5file.close()

        # Check the written data.
        h5file = tables.openFile(self.h5fname)
        arr = h5file.root.test.read()
        h5file.close()

        orig_val = numpy.arange(0, nrows * 2, dtype=numpy.int32) + 0.012
        orig_val.shape = (nrows, 2)
        if common.verbose:
            print "Original values:", orig_val
            print "Retrieved values:", arr
        self.assertTrue(allequal(arr, orig_val),
                        "Stored and retrieved values do not match.")
Exemplo n.º 38
0
    def WriteRead(self, testArray):
        if common.verbose:
            print '\n', '-=' * 30
            print "Running test for array with typecode '%s'" % \
                  testArray.dtype.char,
            print "for class check:", self.title

        # Create an instance of HDF5 Table
        self.file = tempfile.mktemp(".h5")
        self.fileh = openFile(self.file, mode="w")
        self.root = self.fileh.root
        # Create the array under root and name 'somearray'
        a = testArray
        self.fileh.createArray(self.root, 'somearray', a, "Some array")

        # Close the file
        self.fileh.close()

        # Re-open the file in read-only mode
        self.fileh = openFile(self.file, mode="r")
        self.root = self.fileh.root

        # Read the saved array
        b = self.root.somearray.read()
        # For cases that read returns a python type instead of a numpy type
        if not hasattr(b, "shape"):
            b = array(b, dtype=a.dtype.str)

        # Compare them. They should be equal.
        #if not allequal(a,b, "numpy") and common.verbose:
        if common.verbose:
            print "Array written:", a
            print "Array written shape:", a.shape
            print "Array written itemsize:", a.itemsize
            print "Array written type:", a.dtype.char
            print "Array read:", b
            print "Array read shape:", b.shape
            print "Array read itemsize:", b.itemsize
            print "Array read type:", b.dtype.char

        type_ = self.root.somearray.atom.type
        # Check strictly the array equality
        assert type(a) == type(b)
        assert a.shape == b.shape
        assert a.shape == self.root.somearray.shape
        assert a.dtype == b.dtype
        if a.dtype.char[0] == "S":
            assert type_ == "string"
        else:
            assert a.dtype.base.name == type_

        assert allequal(a, b, "numpy")
        self.fileh.close()
        # Then, delete the file
        os.remove(self.file)
        return
Exemplo n.º 39
0
    def WriteRead(self, testArray):
        if common.verbose:
            print '\n', '-=' * 30
            print "Running test for array with typecode '%s'" % \
                  testArray.dtype.char,
            print "for class check:", self.title

        # Create an instance of HDF5 Table
        self.file = tempfile.mktemp(".h5")
        self.fileh = openFile(self.file, mode = "w")
        self.root = self.fileh.root
        # Create the array under root and name 'somearray'
        a = testArray
        self.fileh.createArray(self.root, 'somearray', a, "Some array")

        # Close the file
        self.fileh.close()

        # Re-open the file in read-only mode
        self.fileh = openFile(self.file, mode = "r")
        self.root = self.fileh.root

        # Read the saved array
        b = self.root.somearray.read()
        # For cases that read returns a python type instead of a numpy type
        if not hasattr(b, "shape"):
            b = array(b, dtype=a.dtype.str)

        # Compare them. They should be equal.
        #if not allequal(a,b, "numpy") and common.verbose:
        if common.verbose:
            print "Array written:", a
            print "Array written shape:", a.shape
            print "Array written itemsize:", a.itemsize
            print "Array written type:", a.dtype.char
            print "Array read:", b
            print "Array read shape:", b.shape
            print "Array read itemsize:", b.itemsize
            print "Array read type:", b.dtype.char

        type_ = self.root.somearray.atom.type
        # Check strictly the array equality
        assert type(a) == type(b)
        assert a.shape == b.shape
        assert a.shape == self.root.somearray.shape
        assert a.dtype == b.dtype
        if a.dtype.char[0] == "S":
            assert type_ == "string"
        else:
            assert a.dtype.base.name == type_

        assert allequal(a,b, "numpy")
        self.fileh.close()
        # Then, delete the file
        os.remove(self.file)
        return
Exemplo n.º 40
0
    def test01_readAttr(self):
        """Checking backward compatibility of old formats for attributes."""

        if common.verbose:
            print('\n', '-=' * 30)
            print("Running %s.test01_readAttr..." % self.__class__.__name__)

        # Read old formats
        a = self.h5file.get_node("/a")
        scalar = numpy.array(1, dtype="int32")
        vector = numpy.array([1], dtype="int32")
        if self.format == "1.3":
            self.assertTrue(allequal(a.attrs.arrdim1, vector))
            self.assertTrue(allequal(a.attrs.arrscalar, scalar))
            self.assertEqual(a.attrs.pythonscalar, 1)
        elif self.format == "1.4":
            self.assertTrue(allequal(a.attrs.arrdim1, vector))
            self.assertTrue(allequal(a.attrs.arrscalar, scalar))
            self.assertTrue(allequal(a.attrs.pythonscalar, scalar))
Exemplo n.º 41
0
    def test01_readAttr(self):
        """Checking backward compatibility of old formats for attributes."""

        if common.verbose:
            print('\n', '-=' * 30)
            print("Running %s.test01_readAttr..." % self.__class__.__name__)

        # Read old formats
        a = self.h5file.get_node("/a")
        scalar = numpy.array(1, dtype="int32")
        vector = numpy.array([1], dtype="int32")
        if self.format == "1.3":
            self.assertTrue(allequal(a.attrs.arrdim1, vector))
            self.assertTrue(allequal(a.attrs.arrscalar, scalar))
            self.assertEqual(a.attrs.pythonscalar, 1)
        elif self.format == "1.4":
            self.assertTrue(allequal(a.attrs.arrdim1, vector))
            self.assertTrue(allequal(a.attrs.arrscalar, scalar))
            self.assertTrue(allequal(a.attrs.pythonscalar, scalar))
Exemplo n.º 42
0
    def test00_CompareTable(self):
        "Comparing written unaligned time data with read data in a Table."

        # Create test Table with data.
        h5file = tables.openFile(
                self.h5fname, 'w', title = "Test for comparing Time tables")
        tbl = h5file.createTable('/', 'test', self.MyTimeRow)

        # Size of the test.
        nrows = tbl.nrowsinbuf + 34  # Add some more rows than buffer.
        # Only for home checks; the value above should check better
        # the I/O with multiple buffers.
        ##nrows = 10

        row = tbl.row
        for i in xrange(nrows):
            row['i8col']  = i
            row['t32col'] = i
            j = i * 2
            row['t64col'] = (j+0.012, j+1+0.012)
            row.append()
        h5file.close()

        # Check the written data.
        h5file = tables.openFile(self.h5fname)
        recarr = h5file.root.test.read()
        h5file.close()

        # Int8 column.
        orig_val = numpy.arange(nrows, dtype=numpy.int8)
        if common.verbose:
            print "Original values:", orig_val
            print "Retrieved values:", recarr['i8col'][:]
        self.assert_(
                numpy.alltrue(recarr['i8col'][:] == orig_val),
                "Stored and retrieved values do not match.")

        # Time32 column.
        orig_val = numpy.arange(nrows, dtype=numpy.int32)
        if common.verbose:
            print "Original values:", orig_val
            print "Retrieved values:", recarr['t32col'][:]
        self.assert_(
                numpy.alltrue(recarr['t32col'][:] == orig_val),
                "Stored and retrieved values do not match.")

        # Time64 column.
        orig_val = numpy.arange(0, nrows*2, dtype=numpy.int32) + 0.012
        orig_val.shape = (nrows, 2)
        if common.verbose:
            print "Original values:", orig_val
            print "Retrieved values:", recarr['t64col'][:]
        self.assert_(
            allequal(recarr['t64col'][:], orig_val, numpy.float64),
            "Stored and retrieved values do not match.")
Exemplo n.º 43
0
    def test00_CompareTable(self):
        "Comparing written unaligned time data with read data in a Table."

        # Create test Table with data.
        h5file = tables.openFile(self.h5fname,
                                 'w',
                                 title="Test for comparing Time tables")
        tbl = h5file.createTable('/', 'test', self.MyTimeRow)

        # Size of the test.
        nrows = tbl.nrowsinbuf + 34  # Add some more rows than buffer.
        # Only for home checks; the value above should check better
        # the I/O with multiple buffers.
        ##nrows = 10

        row = tbl.row
        for i in xrange(nrows):
            row['i8col'] = i
            row['t32col'] = i
            j = i * 2
            row['t64col'] = (j + 0.012, j + 1 + 0.012)
            row.append()
        h5file.close()

        # Check the written data.
        h5file = tables.openFile(self.h5fname)
        recarr = h5file.root.test.read()
        h5file.close()

        # Int8 column.
        orig_val = numpy.arange(nrows, dtype=numpy.int8)
        if common.verbose:
            print "Original values:", orig_val
            print "Retrieved values:", recarr['i8col'][:]
        self.assertTrue(numpy.alltrue(recarr['i8col'][:] == orig_val),
                        "Stored and retrieved values do not match.")

        # Time32 column.
        orig_val = numpy.arange(nrows, dtype=numpy.int32)
        if common.verbose:
            print "Original values:", orig_val
            print "Retrieved values:", recarr['t32col'][:]
        self.assertTrue(numpy.alltrue(recarr['t32col'][:] == orig_val),
                        "Stored and retrieved values do not match.")

        # Time64 column.
        orig_val = numpy.arange(0, nrows * 2, dtype=numpy.int32) + 0.012
        orig_val.shape = (nrows, 2)
        if common.verbose:
            print "Original values:", orig_val
            print "Retrieved values:", recarr['t64col'][:]
        self.assertTrue(allequal(recarr['t64col'][:], orig_val, numpy.float64),
                        "Stored and retrieved values do not match.")
Exemplo n.º 44
0
 def test01_read_float16(self):
     dtype = "float16"
     if hasattr(numpy, dtype):
         ds = getattr(self.h5file.root, dtype)
         self.assertFalse(isinstance(ds, tables.UnImplemented))
         self.assertEqual(ds.shape, (self.nrows, self.ncols))
         self.assertEqual(ds.dtype, dtype)
         self.assertTrue(common.allequal(ds.read(), self.values.astype(dtype)))
     else:
         with self.assertWarns(UserWarning):
             ds = getattr(self.h5file.root, dtype)
         self.assertTrue(isinstance(ds, tables.UnImplemented))
Exemplo n.º 45
0
 def test01_read_float16(self):
     dtype = "float16"
     if hasattr(numpy, dtype):
         ds = getattr(self.h5file.root, dtype)
         self.assertFalse(isinstance(ds, tables.UnImplemented))
         self.assertEqual(ds.shape, (self.nrows, self.ncols))
         self.assertEqual(ds.dtype, dtype)
         self.assertTrue(
             common.allequal(ds.read(), self.values.astype(dtype)))
     else:
         with self.assertWarns(UserWarning):
             ds = getattr(self.h5file.root, dtype)
         self.assertTrue(isinstance(ds, tables.UnImplemented))
Exemplo n.º 46
0
    def test01_readAttr(self):
        """Checking backward compatibility of old formats for attributes"""

        if common.verbose:
            print '\n', '-=' * 30
            print "Running %s.test01_readAttr..." % self.__class__.__name__

        # Read old formats
        filename = self._testFilename(self.file)
        self.fileh = open_file(filename % self.format, "r")
        a = self.fileh.get_node("/a")
        scalar = numpy.array(1, dtype="int32")
        vector = numpy.array([1], dtype="int32")
        if self.format == "1.3":
            self.assertTrue(allequal(a.attrs.arrdim1, vector))
            self.assertTrue(allequal(a.attrs.arrscalar, scalar))
            self.assertEqual(a.attrs.pythonscalar, 1)
        elif self.format == "1.4":
            self.assertTrue(allequal(a.attrs.arrdim1, vector))
            self.assertTrue(allequal(a.attrs.arrscalar, scalar))
            self.assertTrue(allequal(a.attrs.pythonscalar, scalar))

        self.fileh.close()
Exemplo n.º 47
0
    def test01_readAttr(self):
        """Checking backward compatibility of old formats for attributes"""

        if common.verbose:
            print '\n', '-=' * 30
            print "Running %s.test01_readAttr..." % self.__class__.__name__

        # Read old formats
        filename = self._testFilename(self.file)
        self.fileh = openFile(filename % self.format, "r")
        a = self.fileh.getNode("/a")
        scalar = numpy.array(1, dtype="int32")
        vector = numpy.array([1], dtype="int32")
        if self.format == "1.3":
            self.assertTrue(allequal(a.attrs.arrdim1, vector))
            self.assertTrue(allequal(a.attrs.arrscalar, scalar))
            self.assertEqual(a.attrs.pythonscalar, 1)
        elif self.format == "1.4":
            self.assertTrue(allequal(a.attrs.arrdim1, vector))
            self.assertTrue(allequal(a.attrs.arrscalar, scalar))
            self.assertTrue(allequal(a.attrs.pythonscalar, scalar))

        self.fileh.close()
Exemplo n.º 48
0
    def test01_Compare64VLArray(self):
        """Comparing written 64-bit time data with read data in a VLArray."""

        wtime = numpy.array((1234567890.123456,) * 2, numpy.float64)

        # Create test VLArray with data.
        vla = self.h5file.create_vlarray('/', 'test', self.myTime64Atom)
        vla.append(wtime)
        self._reopen()

        # Check the written data.
        rtime = self.h5file.root.test.read()[0][0]
        self.h5file.close()
        self.assertTrue(allequal(rtime, wtime),
                        "Stored and retrieved values do not match.")
Exemplo n.º 49
0
    def test01_Compare64VLArray(self):
        """Comparing written 64-bit time data with read data in a VLArray."""

        wtime = np.array((1_234_567_890.123456, ) * 2, np.float64)

        # Create test VLArray with data.
        vla = self.h5file.create_vlarray('/', 'test', self.myTime64Atom)
        vla.append(wtime)
        self._reopen()

        # Check the written data.
        rtime = self.h5file.root.test.read()[0][0]
        self.h5file.close()
        self.assertTrue(common.allequal(rtime, wtime),
                        "Stored and retrieved values do not match.")
Exemplo n.º 50
0
    def test03_Compare64EArray(self):
        """Comparing written 64-bit time data with read data in an EArray."""

        wtime = 1234567890.123456

        # Create test EArray with data.
        ea = self.h5file.create_earray(
            '/', 'test', tables.Time64Atom(), shape=(0,))
        ea.append((wtime,))
        self._reopen()

        # Check the written data.
        rtime = self.h5file.root.test[0]
        self.h5file.close()
        self.assertTrue(allequal(rtime, wtime),
                        "Stored and retrieved values do not match.")
Exemplo n.º 51
0
    def test01_readTableNum(self):
        """Checking column conversion into numarray in read(). Numerical."""

        table = self.fileh.root.table
        table.flavor="numarray"
        for colname in table.colnames:
            numcol = table.read(field=colname)
            typecol = table.coltypes[colname]
            if typecol != "string":
                type_ = numcol.type()
                if common.verbose:
                    print "Type of numarray column read:", type_
                    print "Should look like:", typecol
                orignumcol = ones(shape=self.nrows, dtype=numcol.type())
                # Check that both numarray objects are equal
                self.assertTrue(allequal(numcol, orignumcol, "numarray"))
Exemplo n.º 52
0
    def test03_Compare64EArray(self):
        "Comparing written 64-bit time data with read data in an EArray."

        wtime = 1234567890.123456

        # Create test EArray with data.
        h5file = tables.open_file(self.h5fname, "w", title="Test for comparing Time64 EArrays")
        ea = h5file.create_earray("/", "test", tables.Time64Atom(), shape=(0,))
        ea.append((wtime,))
        h5file.close()

        # Check the written data.
        h5file = tables.open_file(self.h5fname)
        rtime = h5file.root.test[0]
        h5file.close()
        self.assertTrue(allequal(rtime, wtime), "Stored and retrieved values do not match.")
Exemplo n.º 53
0
    def test01_Compare64VLArray(self):
        "Comparing written 64-bit time data with read data in a VLArray."

        wtime = numpy.array((1234567890.123456,) * 2, numpy.float64)

        # Create test VLArray with data.
        h5file = tables.open_file(self.h5fname, "w", title="Test for comparing Time64 VL arrays")
        vla = h5file.create_vlarray("/", "test", self.myTime64Atom)
        vla.append(wtime)
        h5file.close()

        # Check the written data.
        h5file = tables.open_file(self.h5fname)
        rtime = h5file.root.test.read()[0][0]
        h5file.close()
        self.assertTrue(allequal(rtime, wtime), "Stored and retrieved values do not match.")
Exemplo n.º 54
0
    def test01_readTableNum(self):
        """Checking column conversion into NumPy in read(). NumPy flavor"""

        table = self.fileh.root.table
        table.flavor = "numpy"
        for colname in table.colnames:
            numcol = table.read(field=colname)
            typecol = table.coltypes[colname]
            nctypecode = typeNA[numcol.dtype.char[0]]
            if typecol != "string":
                if common.verbose:
                    print "Typecode of NumPy column read:", nctypecode
                    print "Should look like:", typecol
                orignumcol = ones(shape=self.nrows, dtype=numcol.dtype.char)
                # Check that both NumPy objects are equal
                assert allequal(numcol, orignumcol, "numpy")
Exemplo n.º 55
0
    def test02_getWhereList(self):
        """Checking the return of numarray in getWhereList method."""

        if self.close:
            self.fileh.close()
            self.fileh = openFile(self.file, "a")
        table = self.fileh.root.table
        data = table.getWhereList('z == 1')
        if common.verbose:
            print "Type of read:", type(data)
            print "First 3 elements of read:", data[:3]
        # Check that both numarray objects are equal
        self.assertTrue(isinstance(data, NumArray))
        # Check that all columns have been selected
        self.assertEqual(len(data), 100)
        # Finally, check that the contents are ok
        self.assertTrue(allequal(data, arange(100, type="Int64"), "numarray"))
Exemplo n.º 56
0
    def test01_backCompat(self):
        """Checking backward compatibility with old flavors of VLArray"""

        # Open a PYTABLES_FORMAT_VERSION=1.6 file
        filename = self._testFilename("flavored_vlarrays-format1.6.h5")
        fileh = openFile(filename, "r")
        # Check that we can read the contents without problems (nor warnings!)
        vlarray1 = fileh.root.vlarray1
        assert vlarray1.flavor == "numeric"
        if numeric_imported:
            assert allequal(vlarray1[1], Numeric.array([5, 6, 7], typecode='i'),
                            "numeric")
        vlarray2 = fileh.root.vlarray2
        assert vlarray2.flavor == "python"
        assert vlarray2[1] == ['5', '6', '77']

        fileh.close()
Exemplo n.º 57
0
    def test00_Compare32VLArray(self):
        "Comparing written 32-bit time data with read data in a VLArray."

        wtime = numpy.array((1234567890,) * 2, numpy.int32)

        # Create test VLArray with data.
        h5file = tables.openFile(
                self.h5fname, 'w', title = "Test for comparing Time32 VL arrays")
        vla = h5file.createVLArray('/', 'test', self.myTime32Atom)
        vla.append(wtime)
        h5file.close()

        # Check the written data.
        h5file = tables.openFile(self.h5fname)
        rtime = h5file.root.test.read()[0][0]
        h5file.close()
        self.assertTrue(allequal(rtime, wtime),
                        "Stored and retrieved values do not match.")