MCPcopy Create free account
hub / github.com/PyTables/PyTables / test06a

Method test06a

tables/tests/test_tables.py:5043–5082  ·  view source on GitHub ↗

Checking modifying one table row (list version)

(self)

Source from the content-addressed store, hash-verified

5041 self.assertEqual(table.nrows, 4)
5042
5043 def test06a(self):
5044 """Checking modifying one table row (list version)"""
5045
5046 if common.verbose:
5047 print("\n", "-=" * 30)
5048 print("Running %s.test06a..." % self.__class__.__name__)
5049
5050 # Create a new table:
5051 table = self.h5file.create_table(self.h5file.root, "recarray", Rec)
5052
5053 # append new rows
5054 r = np.rec.array(
5055 [(456, b"dbe", 1.2), (2, b"ded", 1.3)], formats="i4,S3,f8"
5056 )
5057 table.append(r)
5058 table.append([(457, b"db1", 1.2), (5, b"de1", 1.3)])
5059 # Modify just one existing rows
5060 table.modify_rows(start=1, rows=[(456, "db1", 1.2)])
5061 # Create the modified recarray
5062 r1 = np.rec.array(
5063 [
5064 (456, b"dbe", 1.2),
5065 (456, b"db1", 1.2),
5066 (457, b"db1", 1.2),
5067 (5, b"de1", 1.3),
5068 ],
5069 formats="i4,S3,f8",
5070 names="col1,col2,col3",
5071 )
5072
5073 # Read the modified table
5074 if self.reopen:
5075 self._reopen()
5076 table = self.h5file.root.recarray
5077 r2 = table.read()
5078 if common.verbose:
5079 print("Original table-->", repr(r2))
5080 print("Should look like-->", repr(r1))
5081 self.assertEqual(r1.tobytes(), r2.tobytes())
5082 self.assertEqual(table.nrows, 4)
5083
5084 def test06b(self):
5085 """Checking modifying one table row (recarray version)"""

Callers

nothing calls this directly

Calls 5

modify_rowsMethod · 0.80
create_tableMethod · 0.45
appendMethod · 0.45
_reopenMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected