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

Method test10a

tables/tests/test_tables.py:5619–5666  ·  view source on GitHub ↗

Checking modifying rows using coordinates (readCoords/modifyCoords).

(self)

Source from the content-addressed store, hash-verified

5617 self.assertEqual(table.nrows, 4)
5618
5619 def test10a(self):
5620 """Checking modifying rows using coordinates
5621 (readCoords/modifyCoords)."""
5622
5623 if common.verbose:
5624 print("\n", "-=" * 30)
5625 print("Running %s.test10a..." % self.__class__.__name__)
5626
5627 # Create a new table:
5628 table = self.h5file.create_table(self.h5file.root, "recarray", Rec)
5629
5630 # append new rows
5631 r = np.rec.array(
5632 [(456, b"dbe", 1.2), (2, b"ded", 1.3)], formats="i4,S3,f8"
5633 )
5634 table.append(r)
5635 table.append([(457, b"db1", 1.2), (5, b"de1", 1.3)])
5636
5637 columns = table.read_coordinates([0, 3])
5638
5639 # Modify both rows
5640 columns["col1"][:] = [55, 56]
5641 columns["col3"][:] = [1.9, 1.8]
5642
5643 # Modify the table in the same coordinates
5644 table.modify_coordinates([0, 3], columns)
5645
5646 # Create the modified recarray
5647 r1 = np.rec.array(
5648 [
5649 (55, b"dbe", 1.9),
5650 (2, b"ded", 1.3),
5651 (457, b"db1", 1.2),
5652 (56, b"de1", 1.8),
5653 ],
5654 formats="i4,S3,f8",
5655 names="col1,col2,col3",
5656 )
5657 # Read the modified table
5658 if self.reopen:
5659 self._reopen()
5660 table = self.h5file.root.recarray
5661 r2 = table.read()
5662 if common.verbose:
5663 print("Original table-->", repr(r2))
5664 print("Should look like-->", repr(r1))
5665 self.assertEqual(r1.tobytes(), r2.tobytes())
5666 self.assertEqual(table.nrows, 4)
5667
5668 def test10b(self):
5669 """Checking modifying rows using coordinates (getitem/setitem)."""

Callers

nothing calls this directly

Calls 6

read_coordinatesMethod · 0.80
modify_coordinatesMethod · 0.80
create_tableMethod · 0.45
appendMethod · 0.45
_reopenMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected