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

Method test08b

tables/tests/test_tables.py:4697–4739  ·  view source on GitHub ↗

Setting values on a large table without calling Row.update

(self)

Source from the content-addressed store, hash-verified

4695 self.assertEqual(table.nrows, nrows)
4696
4697 def test08b(self):
4698 """Setting values on a large table without calling Row.update"""
4699
4700 # Create a new table:
4701 table = self.h5file.create_table(self.h5file.root, "recarray", Rec)
4702 table.nrowsinbuf = self.buffersize # set buffer value
4703
4704 nrows = 100
4705 # append new rows
4706 row = table.row
4707 for i in range(nrows):
4708 row["col1"] = i - 1
4709 row["col2"] = "a" + str(i - 1)
4710 row["col3"] = -1.0
4711 row.append()
4712 table.flush()
4713
4714 # Modify all the rows (actually don't)
4715 for row in table:
4716 row["col1"] = row.nrow
4717 row["col2"] = "b" + str(row.nrow)
4718 row["col3"] = 0.0
4719 # row.update()
4720
4721 # Create the modified recarray
4722 r1 = np.rec.array(
4723 None, shape=nrows, formats="i4,S3,f8", names="col1,col2,col3"
4724 )
4725 for i in range(nrows):
4726 r1["col1"][i] = i - 1
4727 r1["col2"][i] = "a" + str(i - 1)
4728 r1["col3"][i] = -1.0
4729 # Read the modified table
4730 if self.reopen:
4731 self._reopen()
4732 table = self.h5file.root.recarray
4733 table.nrowsinbuf = self.buffersize # set buffer value
4734 r2 = table.read()
4735 if common.verbose:
4736 print("Original table-->", repr(r2))
4737 print("Should look like-->", repr(r1))
4738 self.assertEqual(r1.tobytes(), r2.tobytes())
4739 self.assertEqual(table.nrows, nrows)
4740
4741 def test09(self):
4742 """Modifying selected values on a large table"""

Callers

nothing calls this directly

Calls 5

create_tableMethod · 0.45
appendMethod · 0.45
flushMethod · 0.45
_reopenMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected