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

Method test09a

tables/tests/test_tables.py:5445–5486  ·  view source on GitHub ↗

Checking modifying table columns (multiple column version)

(self)

Source from the content-addressed store, hash-verified

5443 self.assertEqual(table.nrows, 4)
5444
5445 def test09a(self):
5446 """Checking modifying table columns (multiple column version)"""
5447
5448 if common.verbose:
5449 print("\n", "-=" * 30)
5450 print("Running %s.test09a..." % self.__class__.__name__)
5451
5452 # Create a new table:
5453 table = self.h5file.create_table(self.h5file.root, "recarray", Rec)
5454
5455 # append new rows
5456 r = np.rec.array(
5457 [(456, b"dbe", 1.2), (2, b"ded", 1.3)], formats="i4,S3,f8"
5458 )
5459 table.append(r)
5460 table.append([(457, b"db1", 1.2), (5, b"de1", 1.3)])
5461
5462 # Modify a couple of columns
5463 columns = [["aaa", "bbb", "ccc"], [1.2, 0.1, 0.3]]
5464 table.modify_columns(start=1, columns=columns, names=["col2", "col3"])
5465 # Create the modified recarray
5466 r1 = np.rec.array(
5467 [
5468 (456, b"dbe", 1.2),
5469 (2, b"aaa", 1.2),
5470 (457, b"bbb", 0.1),
5471 (5, b"ccc", 0.3),
5472 ],
5473 formats="i4,S3,f8",
5474 names="col1,col2,col3",
5475 )
5476
5477 # Read the modified table
5478 if self.reopen:
5479 self._reopen()
5480 table = self.h5file.root.recarray
5481 r2 = table.read()
5482 if common.verbose:
5483 print("Original table-->", repr(r2))
5484 print("Should look like-->", repr(r1))
5485 self.assertEqual(r1.tobytes(), r2.tobytes())
5486 self.assertEqual(table.nrows, 4)
5487
5488 def test09b(self):
5489 """Checking modifying table columns (multiple columns, recarray)"""

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