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

Method test08b

tables/tests/test_tablesMD.py:1245–1294  ·  view source on GitHub ↗

Checking modifying one column (single column version, recarray)

(self)

Source from the content-addressed store, hash-verified

1243 self.assertEqual(table.nrows, 4)
1244
1245 def test08b(self):
1246 """Checking modifying one column (single column version, recarray)"""
1247
1248 if common.verbose:
1249 print("\n", "-=" * 30)
1250 print("Running %s.test08b..." % self.__class__.__name__)
1251
1252 # Create a new table:
1253 table = self.h5file.create_table(self.h5file.root, "recarray", Rec)
1254
1255 # Append new rows
1256 s0, s1, s2, s3 = ["dbe"] * 3, ["ded"] * 3, ["db1"] * 3, ["de1"] * 3
1257 f0, f1, f2, f3 = (
1258 [[1.2] * 2] * 3,
1259 [[1.3] * 2] * 3,
1260 [[1.4] * 2] * 3,
1261 [[1.5] * 2] * 3,
1262 )
1263 r = np.rec.array(
1264 [([456, 457], s0, f0), ([2, 3], s1, f1)],
1265 formats="(2,)i4,(3,)S3,(3,2)f8",
1266 )
1267 table.append(r)
1268 table.append([([457, 458], s2, f2), ([5, 6], s3, f3)])
1269
1270 # Modify just one existing column
1271 columns = np.rec.fromarrays(
1272 np.array([[[2, 3], [3, 4], [4, 5]]]), formats="i4"
1273 )
1274 table.modify_columns(start=1, columns=columns, names=["col1"])
1275
1276 # Create the modified recarray
1277 r1 = np.rec.array(
1278 [
1279 ([456, 457], s0, f0),
1280 ([2, 3], s1, f1),
1281 ([3, 4], s2, f2),
1282 ([4, 5], s3, f3),
1283 ],
1284 formats="(2,)i4,(3,)S3,(3,2)f8",
1285 names="col1,col2,col3",
1286 )
1287
1288 # Read the modified table
1289 r2 = table.read()
1290 if common.verbose:
1291 print("Original table-->", repr(r2))
1292 print("Should look like-->", repr(r1))
1293 self.assertEqual(r1.tobytes(), r2.tobytes())
1294 self.assertEqual(table.nrows, 4)
1295
1296 def test08b2(self):
1297 """Checking modifying one column (single column version, recarray,

Callers

nothing calls this directly

Calls 4

modify_columnsMethod · 0.80
create_tableMethod · 0.45
appendMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected