本文整理汇总了Python中tables.tests.common.allequal函数的典型用法代码示例。如果您正苦于以下问题:Python allequal函数的具体用法?Python allequal怎么用?Python allequal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了allequal函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test03_read_float64
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: test01_read_float16
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: test08a_modifyingRows
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: test01a_basicTableRead
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: test03_read_float64
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: test07b_modifyingRows
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: test03b_Compare64EArray
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: _test
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: test02_readCoordsChar
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: test07a_modifyingRows
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: test01b_Compare64VLArray
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: _test
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: test04_read_longdouble
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: test08b_modifyingRows
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: test05b_modifyingColumns
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"))