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

Method test02a

tables/tests/test_nestedtypes.py:1528–1580  ·  view source on GitHub ↗

Indexing two simple columns under the same nested column.

(self)

Source from the content-addressed store, hash-verified

1526 )
1527
1528 def test02a(self):
1529 """Indexing two simple columns under the same nested column."""
1530
1531 desc = {"nested": {"i1": tb.Int32Col(), "i2": tb.Int32Col()}}
1532
1533 i1 = "nested/i1"
1534 i2 = "nested/i2"
1535 tbl = self.h5file.create_table(
1536 "/", "test", desc, title=self._getMethodName()
1537 )
1538
1539 row = tbl.row
1540 for i in range(1000):
1541 row[i1] = i
1542 row[i2] = i * 2
1543 row.append()
1544 tbl.flush()
1545
1546 cols = {
1547 "i1": tbl.cols.nested.i1,
1548 "i2": tbl.cols.nested.i2,
1549 }
1550 cols["i1"].create_index()
1551 cols["i2"].create_index()
1552
1553 if self.reopen:
1554 self._reopen()
1555 tbl = self.h5file.root.test
1556 # Redefine the cols dictionary
1557 cols = {
1558 "i1": tbl.cols.nested.i1,
1559 "i2": tbl.cols.nested.i2,
1560 }
1561
1562 i1res = [r[i1] for r in tbl.where("i1 < 10", cols)]
1563 i2res = [r[i2] for r in tbl.where("i2 < 10", cols)]
1564
1565 if common.verbose:
1566 print("Retrieved values (i1):", i1res)
1567 print("Should look like:", list(range(10)))
1568 print("Retrieved values (i2):", i2res)
1569 print("Should look like:", list(range(0, 10, 2)))
1570
1571 self.assertEqual(
1572 i1res,
1573 list(range(10)),
1574 "Select for nested column (i1) doesn't match.",
1575 )
1576 self.assertEqual(
1577 i2res,
1578 list(range(0, 10, 2)),
1579 "Select for nested column (i2) doesn't match.",
1580 )
1581
1582 def test02b(self):
1583 """Indexing two simple columns under the same (very) nested column."""

Callers

nothing calls this directly

Calls 7

_getMethodNameMethod · 0.80
create_indexMethod · 0.80
whereMethod · 0.80
create_tableMethod · 0.45
appendMethod · 0.45
flushMethod · 0.45
_reopenMethod · 0.45

Tested by

no test coverage detected