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

Method test08b

tables/tests/test_tables.py:5316–5356  ·  view source on GitHub ↗

Checking modifying one column (single column version, recarray)

(self)

Source from the content-addressed store, hash-verified

5314 self.assertEqual(table.nrows, 4)
5315
5316 def test08b(self):
5317 """Checking modifying one column (single column version, recarray)"""
5318
5319 if common.verbose:
5320 print("\n", "-=" * 30)
5321 print("Running %s.test08b..." % self.__class__.__name__)
5322
5323 # Create a new table:
5324 table = self.h5file.create_table(self.h5file.root, "recarray", Rec)
5325
5326 # append new rows
5327 r = np.rec.array(
5328 [(456, b"dbe", 1.2), (2, b"ded", 1.3)], formats="i4,S3,f8"
5329 )
5330 table.append(r)
5331 table.append([(457, b"db1", 1.2), (5, b"de1", 1.3)])
5332
5333 # Modify just one existing column
5334 columns = np.rec.fromarrays(np.array([[2, 3, 4]]), formats="i4")
5335 table.modify_columns(start=1, columns=columns, names=["col1"])
5336 # Create the modified recarray
5337 r1 = np.rec.array(
5338 [
5339 (456, b"dbe", 1.2),
5340 (2, b"ded", 1.3),
5341 (3, b"db1", 1.2),
5342 (4, b"de1", 1.3),
5343 ],
5344 formats="i4,S3,f8",
5345 names="col1,col2,col3",
5346 )
5347 # Read the modified table
5348 if self.reopen:
5349 self._reopen()
5350 table = self.h5file.root.recarray
5351 r2 = table.read()
5352 if common.verbose:
5353 print("Original table-->", repr(r2))
5354 print("Should look like-->", repr(r1))
5355 self.assertEqual(r1.tobytes(), r2.tobytes())
5356 self.assertEqual(table.nrows, 4)
5357
5358 def test08b2(self):
5359 """Checking modifying one column (single column version, 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