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

Method test08b2

tables/tests/test_tables.py:5358–5399  ·  view source on GitHub ↗

Checking modifying one column (single column version, recarray, modify_column)

(self)

Source from the content-addressed store, hash-verified

5356 self.assertEqual(table.nrows, 4)
5357
5358 def test08b2(self):
5359 """Checking modifying one column (single column version, recarray,
5360 modify_column)"""
5361
5362 if common.verbose:
5363 print("\n", "-=" * 30)
5364 print("Running %s.test08b2..." % self.__class__.__name__)
5365
5366 # Create a new table:
5367 table = self.h5file.create_table(self.h5file.root, "recarray", Rec)
5368
5369 # append new rows
5370 r = np.rec.array(
5371 [(456, b"dbe", 1.2), (2, b"ded", 1.3)], formats="i4,S3,f8"
5372 )
5373 table.append(r)
5374 table.append([(457, b"db1", 1.2), (5, b"de1", 1.3)])
5375
5376 # Modify just one existing column
5377 columns = np.rec.fromarrays(np.array([[2, 3, 4]]), formats="i4")
5378 table.modify_column(start=1, column=columns, colname="col1")
5379 # Create the modified recarray
5380 r1 = np.rec.array(
5381 [
5382 (456, b"dbe", 1.2),
5383 (2, b"ded", 1.3),
5384 (3, b"db1", 1.2),
5385 (4, b"de1", 1.3),
5386 ],
5387 formats="i4,S3,f8",
5388 names="col1,col2,col3",
5389 )
5390 # Read the modified table
5391 if self.reopen:
5392 self._reopen()
5393 table = self.h5file.root.recarray
5394 r2 = table.read()
5395 if common.verbose:
5396 print("Original table-->", repr(r2))
5397 print("Should look like-->", repr(r1))
5398 self.assertEqual(r1.tobytes(), r2.tobytes())
5399 self.assertEqual(table.nrows, 4)
5400
5401 def test08c(self):
5402 """Checking modifying one column (single column version,

Callers

nothing calls this directly

Calls 5

modify_columnMethod · 0.80
create_tableMethod · 0.45
appendMethod · 0.45
_reopenMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected