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

Method test01a_String

tables/tests/test_carray.py:1436–1470  ·  view source on GitHub ↗

Checking carray with offset NumPy strings appends.

(self)

Source from the content-addressed store, hash-verified

1434 self.rootgroup = self.h5file.root
1435
1436 def test01a_String(self):
1437 """Checking carray with offset NumPy strings appends."""
1438
1439 root = self.rootgroup
1440 if common.verbose:
1441 print("\n", "-=" * 30)
1442 print("Running %s.test01a_String..." % self.__class__.__name__)
1443
1444 shape = (3, 2, 2)
1445 # Create a string atom
1446 carray = self.h5file.create_carray(
1447 root,
1448 "strings",
1449 atom=tb.StringAtom(itemsize=3),
1450 shape=shape,
1451 title="Array of strings",
1452 chunkshape=(1, 2, 2),
1453 )
1454 a = np.array([[["a", "b"], ["123", "45"], ["45", "123"]]], dtype="S3")
1455 carray[0] = a[0, 1:]
1456 a = np.array([[["s", "a"], ["ab", "f"], ["s", "abc"], ["abc", "f"]]])
1457 carray[1] = a[0, 2:]
1458
1459 # Read all the data:
1460 data = carray.read()
1461 if common.verbose:
1462 print("Object read:", data)
1463 print("Nrows in", carray._v_pathname, ":", carray.nrows)
1464 print("Second row in carray ==>", data[1].tolist())
1465
1466 self.assertEqual(carray.nrows, 3)
1467 self.assertEqual(data[0].tolist(), [[b"123", b"45"], [b"45", b"123"]])
1468 self.assertEqual(data[1].tolist(), [[b"s", b"abc"], [b"abc", b"f"]])
1469 self.assertEqual(len(data[0]), 2)
1470 self.assertEqual(len(data[1]), 2)
1471
1472 def test01b_String(self):
1473 """Checking carray with strided NumPy strings appends."""

Callers

nothing calls this directly

Calls 2

create_carrayMethod · 0.80
readMethod · 0.45

Tested by

no test coverage detected