Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions doc/source/user_guide/cookbook.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,25 @@ Storing Attributes to a group node
store.close()
os.remove('test.h5')

You can create or load a HDFStore in-memory by passing the ``driver``
parameter to PyTables. Changes are only written to disk when the HDFStore
is closed.

.. ipython:: python

store = pd.HDFStore('test.h5', 'w', diver='H5FD_CORE')

df = pd.DataFrame(np.random.randn(8, 3))
store['test'] = df

# only after closing the store, data is written to disk:
store.close()

.. ipython:: python
:suppress:

os.remove('test.h5')

.. _cookbook.binary:

Binary files
Expand Down
39 changes: 27 additions & 12 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,8 @@ class HDFStore:

Parameters
----------
path : string
File path to HDF5 file
path : str
File path to HDF5 file.
mode : {'a', 'w', 'r', 'r+'}, default 'a'

``'r'``
Expand All @@ -462,18 +462,20 @@ class HDFStore:
``'r+'``
It is similar to ``'a'``, but the file must already exist.
complevel : int, 0-9, default None
Specifies a compression level for data.
A value of 0 or None disables compression.
Specifies a compression level for data.
A value of 0 or None disables compression.
complib : {'zlib', 'lzo', 'bzip2', 'blosc'}, default 'zlib'
Specifies the compression library to be used.
As of v0.20.2 these additional compressors for Blosc are supported
(default if no compressor specified: 'blosc:blosclz'):
{'blosc:blosclz', 'blosc:lz4', 'blosc:lz4hc', 'blosc:snappy',
'blosc:zlib', 'blosc:zstd'}.
Specifying a compression library which is not available issues
a ValueError.
Specifies the compression library to be used.
As of v0.20.2 these additional compressors for Blosc are supported
(default if no compressor specified: 'blosc:blosclz'):
{'blosc:blosclz', 'blosc:lz4', 'blosc:lz4hc', 'blosc:snappy',
'blosc:zlib', 'blosc:zstd'}.
Specifying a compression library which is not available issues
a ValueError.
fletcher32 : bool, default False
If applying compression use the fletcher32 checksum
If applying compression use the fletcher32 checksum.
**kwargs
These parameters will be passed to the PyTables open_file method.

Examples
--------
Expand All @@ -482,6 +484,17 @@ class HDFStore:
>>> store['foo'] = bar # write to HDF5
>>> bar = store['foo'] # retrieve
>>> store.close()

**Create or load HDF5 file in-memory**

When passing the `driver` option to the PyTables open_file method through
**kwargs, the HDF5 file is loaded or created in-memory and will only be
written when closed:

>>> bar = pd.DataFrame(np.random.randn(10, 4))
>>> store = pd.HDFStore('test.h5', driver='H5FD_CORE')
>>> store['foo'] = bar
>>> store.close() # only now, data is written to disk
"""

_handle: Optional["File"]
Expand Down Expand Up @@ -634,6 +647,8 @@ def open(self, mode: str = "a", **kwargs):
----------
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 method.
"""
tables = _tables()

Expand Down