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

Method test01b_String

tables/tests/test_carray.py:1472–1507  ·  view source on GitHub ↗

Checking carray with strided NumPy strings appends.

(self)

Source from the content-addressed store, hash-verified

1470 self.assertEqual(len(data[1]), 2)
1471
1472 def test01b_String(self):
1473 """Checking carray with strided NumPy strings appends."""
1474
1475 root = self.rootgroup
1476 if common.verbose:
1477 print("\n", "-=" * 30)
1478 print("Running %s.test01b_String..." % self.__class__.__name__)
1479
1480 shape = (3, 2, 2)
1481
1482 # Create a string atom
1483 carray = self.h5file.create_carray(
1484 root,
1485 "strings",
1486 atom=tb.StringAtom(itemsize=3),
1487 shape=shape,
1488 title="Array of strings",
1489 chunkshape=(1, 2, 2),
1490 )
1491 a = np.array([[["a", "b"], ["123", "45"], ["45", "123"]]], dtype="S3")
1492 carray[0] = a[0, ::2]
1493 a = np.array([[["s", "a"], ["ab", "f"], ["s", "abc"], ["abc", "f"]]])
1494 carray[1] = a[0, ::2]
1495
1496 # Read all the rows:
1497 data = carray.read()
1498 if common.verbose:
1499 print("Object read:", data)
1500 print("Nrows in", carray._v_pathname, ":", carray.nrows)
1501 print("Second row in carray ==>", data[1].tolist())
1502
1503 self.assertEqual(carray.nrows, 3)
1504 self.assertEqual(data[0].tolist(), [[b"a", b"b"], [b"45", b"123"]])
1505 self.assertEqual(data[1].tolist(), [[b"s", b"a"], [b"s", b"abc"]])
1506 self.assertEqual(len(data[0]), 2)
1507 self.assertEqual(len(data[1]), 2)
1508
1509 def test02a_int(self):
1510 """Checking carray with offset NumPy ints appends."""

Callers

nothing calls this directly

Calls 2

create_carrayMethod · 0.80
readMethod · 0.45

Tested by

no test coverage detected