Open the file in the specified mode Parameters ---------- mode : {'a', 'w', 'r', 'r+'}, default 'a' See HDFStore docstring or tables.open_file for info about modes **kwargs These parameters will be passed to the PyTables open_file met
(self, mode: str = "a", **kwargs)
| 718 | yield g._v_pathname, g |
| 719 | |
| 720 | def open(self, mode: str = "a", **kwargs) -> None: |
| 721 | """ |
| 722 | Open the file in the specified mode |
| 723 | |
| 724 | Parameters |
| 725 | ---------- |
| 726 | mode : {'a', 'w', 'r', 'r+'}, default 'a' |
| 727 | See HDFStore docstring or tables.open_file for info about modes |
| 728 | **kwargs |
| 729 | These parameters will be passed to the PyTables open_file method. |
| 730 | """ |
| 731 | tables = _tables() |
| 732 | |
| 733 | if self._mode != mode: |
| 734 | # if we are changing a write mode to read, ok |
| 735 | if self._mode in ["a", "w"] and mode in ["r", "r+"]: |
| 736 | pass |
| 737 | elif mode in ["w"]: |
| 738 | # this would truncate, raise here |
| 739 | if self.is_open: |
| 740 | raise PossibleDataLossError( |
| 741 | f"Re-opening the file [{self._path}] with mode [{self._mode}] " |
| 742 | "will delete the current file!" |
| 743 | ) |
| 744 | |
| 745 | self._mode = mode |
| 746 | |
| 747 | # close and reopen the handle |
| 748 | if self.is_open: |
| 749 | self.close() |
| 750 | |
| 751 | if self._complevel and self._complevel > 0: |
| 752 | self._filters = _tables().Filters( |
| 753 | self._complevel, self._complib, fletcher32=self._fletcher32 |
| 754 | ) |
| 755 | |
| 756 | if _table_file_open_policy_is_strict and self.is_open: |
| 757 | msg = ( |
| 758 | "Cannot open HDF5 file, which is already opened, " |
| 759 | "even in read-only mode." |
| 760 | ) |
| 761 | raise ValueError(msg) |
| 762 | |
| 763 | self._handle = tables.open_file(self._path, self._mode, **kwargs) |
| 764 | |
| 765 | def close(self) -> None: |
| 766 | """ |