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

Method test09b

tables/tests/test_tables.py:5488–5530  ·  view source on GitHub ↗

Checking modifying table columns (multiple columns, recarray)

(self)

Source from the content-addressed store, hash-verified

5486 self.assertEqual(table.nrows, 4)
5487
5488 def test09b(self):
5489 """Checking modifying table columns (multiple columns, recarray)"""
5490
5491 if common.verbose:
5492 print("\n", "-=" * 30)
5493 print("Running %s.test09b..." % self.__class__.__name__)
5494
5495 # Create a new table:
5496 table = self.h5file.create_table(self.h5file.root, "recarray", Rec)
5497
5498 # append new rows
5499 r = np.rec.array(
5500 [(456, b"dbe", 1.2), (2, b"ded", 1.3)], formats="i4,S3,f8"
5501 )
5502 table.append(r)
5503 table.append([(457, b"db1", 1.2), (5, b"de1", 1.3)])
5504
5505 # Modify a couple of columns
5506 columns = np.rec.array(
5507 [("aaa", 1.2), ("bbb", 0.1), ("ccc", 0.3)], formats="S3,f8"
5508 )
5509 table.modify_columns(start=1, columns=columns, names=["col2", "col3"])
5510 # Create the modified recarray
5511 r1 = np.rec.array(
5512 [
5513 (456, "dbe", 1.2),
5514 (2, "aaa", 1.2),
5515 (457, "bbb", 0.1),
5516 (5, "ccc", 0.3),
5517 ],
5518 formats="i4,S3,f8",
5519 names="col1,col2,col3",
5520 )
5521 # Read the modified table
5522 if self.reopen:
5523 self._reopen()
5524 table = self.h5file.root.recarray
5525 r2 = table.read()
5526 if common.verbose:
5527 print("Original table-->", repr(r2))
5528 print("Should look like-->", repr(r1))
5529 self.assertEqual(r1.tobytes(), r2.tobytes())
5530 self.assertEqual(table.nrows, 4)
5531
5532 def test09c(self):
5533 """Checking modifying table columns (single column, step)"""

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