Walk the pytables group hierarchy for pandas objects. This generator will yield the group path, subgroups and pandas object names for each group. Any non-pandas PyTables objects that are not a group will be ignored. The `where` group itself is listed first
(self, where: str = "/")
| 1596 | ] |
| 1597 | |
| 1598 | def walk(self, where: str = "/") -> Iterator[tuple[str, list[str], list[str]]]: |
| 1599 | """ |
| 1600 | Walk the pytables group hierarchy for pandas objects. |
| 1601 | |
| 1602 | This generator will yield the group path, subgroups and pandas object |
| 1603 | names for each group. |
| 1604 | |
| 1605 | Any non-pandas PyTables objects that are not a group will be ignored. |
| 1606 | |
| 1607 | The `where` group itself is listed first (preorder), then each of its |
| 1608 | child groups (following an alphanumerical order) is also traversed, |
| 1609 | following the same procedure. |
| 1610 | |
| 1611 | Parameters |
| 1612 | ---------- |
| 1613 | where : str, default "/" |
| 1614 | Group where to start walking. |
| 1615 | |
| 1616 | Yields |
| 1617 | ------ |
| 1618 | path : str |
| 1619 | Full path to a group (without trailing '/'). |
| 1620 | groups : list |
| 1621 | Names (strings) of the groups contained in `path`. |
| 1622 | leaves : list |
| 1623 | Names (strings) of the pandas objects contained in `path`. |
| 1624 | |
| 1625 | See Also |
| 1626 | -------- |
| 1627 | HDFStore.info : Prints detailed information on the store. |
| 1628 | |
| 1629 | Examples |
| 1630 | -------- |
| 1631 | >>> df1 = pd.DataFrame([[1, 2], [3, 4]], columns=["A", "B"]) |
| 1632 | >>> store = pd.HDFStore("store.h5", "w") # doctest: +SKIP |
| 1633 | >>> store.put("data", df1, format="table") # doctest: +SKIP |
| 1634 | >>> df2 = pd.DataFrame([[5, 6], [7, 8]], columns=["A", "B"]) |
| 1635 | >>> store.append("data", df2) # doctest: +SKIP |
| 1636 | >>> store.close() # doctest: +SKIP |
| 1637 | >>> for group in store.walk(): # doctest: +SKIP |
| 1638 | ... print(group) # doctest: +SKIP |
| 1639 | >>> store.close() # doctest: +SKIP |
| 1640 | """ |
| 1641 | _tables() |
| 1642 | self._check_if_open() |
| 1643 | assert self._handle is not None # for mypy |
| 1644 | assert _table_mod is not None # for mypy |
| 1645 | |
| 1646 | for g in self._handle.walk_groups(where): |
| 1647 | if getattr(g._v_attrs, "pandas_type", None) is not None: |
| 1648 | continue |
| 1649 | |
| 1650 | groups = [] |
| 1651 | leaves = [] |
| 1652 | for child in g._v_children.values(): |
| 1653 | pandas_type = getattr(child._v_attrs, "pandas_type", None) |
| 1654 | if pandas_type is None: |
| 1655 | if isinstance(child, _table_mod.group.Group): |