コード例 #1
0
ファイル: test_types.py プロジェクト: andreas-h/PyTables
 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)
コード例 #2
0
ファイル: test_types.py プロジェクト: andreas-h/PyTables
 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))
コード例 #3
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")
コード例 #4
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)
コード例 #5
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)))
コード例 #6
0
ファイル: test_numpy.py プロジェクト: ilustreous/PyTables
    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")
コード例 #7
0
ファイル: test_timetype.py プロジェクト: andreas-h/PyTables
    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.")
コード例 #8
0
ファイル: test_hdf5compat.py プロジェクト: vkarthi46/PyTables
    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()
コード例 #9
0
ファイル: test_Numeric.py プロジェクト: andreas-h/PyTables
    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"))
コード例 #10
0
ファイル: test_numarray.py プロジェクト: andreas-h/PyTables
    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"))
コード例 #11
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.")
コード例 #12
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()
コード例 #13
0
ファイル: test_types.py プロジェクト: B-Rich/PyTables
    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")
コード例 #14
0
ファイル: test_numarray.py プロジェクト: andreas-h/PyTables
    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"))
コード例 #15
0
ファイル: test_numarray.py プロジェクト: andreas-h/PyTables
    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"))
コード例 #16
0
ファイル: test_numarray.py プロジェクト: andreas-h/PyTables
    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))
コード例 #17
0
ファイル: test_numpy.py プロジェクト: ilustreous/PyTables
    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
コード例 #18
0
ファイル: test_backcompat.py プロジェクト: ESSS/PyTables
    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))
コード例 #19
0
ファイル: test_timetype.py プロジェクト: ilustreous/PyTables
    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.")
コード例 #20
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))
コード例 #21
0
ファイル: test_backcompat.py プロジェクト: 87/PyTables
    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()
コード例 #22
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.")
コード例 #23
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.")
コード例 #24
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.")
コード例 #25
0
ファイル: test_numpy.py プロジェクト: ilustreous/PyTables
    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")
コード例 #26
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.")
コード例 #27
0
ファイル: test_numarray.py プロジェクト: andreas-h/PyTables
    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"))
コード例 #28
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()
コード例 #29
0
ファイル: test_numarray.py プロジェクト: andreas-h/PyTables
    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"))
コード例 #30
0
ファイル: test_timetype.py プロジェクト: andreas-h/PyTables
    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.")