MCPcopy
hub / github.com/pandas-dev/pandas / open

Method open

pandas/io/pytables.py:720–763  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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 """

Callers 13

__init__Method · 0.95
test_reopen_handleFunction · 0.95
generate_pip_from_condaFunction · 0.45
_open_browserMethod · 0.45
blog_add_postsMethod · 0.45
roadmap_pdepsMethod · 0.45
get_contextFunction · 0.45
mainFunction · 0.45
writeMethod · 0.45
readMethod · 0.45
_get_filepath_or_bufferFunction · 0.45
get_handleFunction · 0.45

Calls 3

closeMethod · 0.95
_tablesFunction · 0.85

Tested by 1

test_reopen_handleFunction · 0.76