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

Method test08_AppendModifyRows

tables/tests/test_tables.py:2143–2339  ·  view source on GitHub ↗

Checking whether blosc2 optimized appending *and* reading rows works or not

(self)

Source from the content-addressed store, hash-verified

2141 self.assertEqual(row[2], b"." * 4)
2142
2143 def test08_AppendModifyRows(self):
2144 """Checking whether blosc2 optimized appending *and* reading rows works or not"""
2145
2146 class Particle(tb.IsDescription):
2147 name = tb.StringCol(16, pos=1) # 16-character String
2148 lati = tb.Int32Col(pos=2) # integer
2149 longi = tb.Int32Col(pos=3) # integer
2150 pressure = tb.Float32Col(pos=4) # float (single-precision)
2151 temperature = tb.Float64Col(pos=5) # double (double-precision)
2152
2153 # Now, open it, but in "append" mode
2154 self.h5file = tb.open_file(self.h5fname, mode="a")
2155
2156 # Create a new group
2157 group = self.h5file.create_group(self.h5file.root, "newgroup")
2158
2159 # Create a new table in newgroup group
2160 table = self.h5file.create_table(
2161 group,
2162 "table",
2163 Particle,
2164 "A table",
2165 tb.Filters(
2166 complevel=self.compress,
2167 shuffle=bool(self.shuffle),
2168 bitshuffle=bool(self.bitshuffle),
2169 complib=self.complib,
2170 ),
2171 chunkshape=3,
2172 )
2173
2174 self.rootgroup = self.h5file.root.newgroup
2175 if common.verbose:
2176 print("\n", "-=" * 30)
2177 print(
2178 "Running %s.test08_AppendModifyRows..."
2179 % self.__class__.__name__
2180 )
2181
2182 if common.verbose:
2183 print("Nrows in old", table._v_pathname, ":", table.nrows)
2184 print("Record Format ==>", table.description._v_nested_formats)
2185 print("Record Size ==>", table.rowsize)
2186
2187 # Add a couple of user attrs
2188 table.attrs.user_attr1 = 1.023
2189 table.attrs.user_attr2 = "This is the second user attr"
2190
2191 # Append several rows in only one call
2192 for j in range(200):
2193 i = 13 * j
2194 table.append(
2195 [(f"Particle: {i:6d}", i, 10 - i, float(i * i), float(i**2))]
2196 )
2197
2198 table.append(
2199 [
2200 (

Callers

nothing calls this directly

Calls 7

create_groupMethod · 0.80
modify_rowsMethod · 0.80
popMethod · 0.80
create_tableMethod · 0.45
appendMethod · 0.45
closeMethod · 0.45
iterrowsMethod · 0.45

Tested by

no test coverage detected