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

Method test09d

tables/tests/test_tables.py:5575–5617  ·  view source on GitHub ↗

Checking modifying table columns (multiple columns, step)

(self)

Source from the content-addressed store, hash-verified

5573 self.assertEqual(table.nrows, 4)
5574
5575 def test09d(self):
5576 """Checking modifying table columns (multiple columns, step)"""
5577
5578 if common.verbose:
5579 print("\n", "-=" * 30)
5580 print("Running %s.test09d..." % self.__class__.__name__)
5581
5582 # Create a new table:
5583 table = self.h5file.create_table(self.h5file.root, "recarray", Rec)
5584
5585 # append new rows
5586 r = np.rec.array(
5587 [(456, b"dbe", 1.2), (2, b"ded", 1.3)], formats="i4,S3,f8"
5588 )
5589 table.append(r)
5590 table.append([(457, b"db1", 1.2), (5, b"de1", 1.3)])
5591
5592 # Modify a couple of columns
5593 columns = np.rec.array([("aaa", 1.3), ("bbb", 0.1)], formats="S3,f8")
5594 table.modify_columns(
5595 start=0, step=2, columns=columns, names=["col2", "col3"]
5596 )
5597 # Create the modified recarray
5598 r1 = np.rec.array(
5599 [
5600 (456, "aaa", 1.3),
5601 (2, "ded", 1.3),
5602 (457, "bbb", 0.1),
5603 (5, "de1", 1.3),
5604 ],
5605 formats="i4,S3,f8",
5606 names="col1,col2,col3",
5607 )
5608 # Read the modified table
5609 if self.reopen:
5610 self._reopen()
5611 table = self.h5file.root.recarray
5612 r2 = table.read()
5613 if common.verbose:
5614 print("Original table-->", repr(r2))
5615 print("Should look like-->", repr(r1))
5616 self.assertEqual(r1.tobytes(), r2.tobytes())
5617 self.assertEqual(table.nrows, 4)
5618
5619 def test10a(self):
5620 """Checking modifying rows using coordinates

Callers

nothing calls this directly

Calls 5

modify_columnsMethod · 0.80
create_tableMethod · 0.45
appendMethod · 0.45
_reopenMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected