Skip to content

Commit 60691da

Browse files
DOC: document support for in-memory HDFStore GH33166 (#34888)
1 parent 528148f commit 60691da

File tree

2 files changed

+46
-12
lines changed

2 files changed

+46
-12
lines changed

doc/source/user_guide/cookbook.rst

+19
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,25 @@ Storing Attributes to a group node
11661166
store.close()
11671167
os.remove('test.h5')
11681168
1169+
You can create or load a HDFStore in-memory by passing the ``driver``
1170+
parameter to PyTables. Changes are only written to disk when the HDFStore
1171+
is closed.
1172+
1173+
.. ipython:: python
1174+
1175+
store = pd.HDFStore('test.h5', 'w', diver='H5FD_CORE')
1176+
1177+
df = pd.DataFrame(np.random.randn(8, 3))
1178+
store['test'] = df
1179+
1180+
# only after closing the store, data is written to disk:
1181+
store.close()
1182+
1183+
.. ipython:: python
1184+
:suppress:
1185+
1186+
os.remove('test.h5')
1187+
11691188
.. _cookbook.binary:
11701189

11711190
Binary files

pandas/io/pytables.py

+27-12
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,8 @@ class HDFStore:
447447
448448
Parameters
449449
----------
450-
path : string
451-
File path to HDF5 file
450+
path : str
451+
File path to HDF5 file.
452452
mode : {'a', 'w', 'r', 'r+'}, default 'a'
453453
454454
``'r'``
@@ -462,18 +462,20 @@ class HDFStore:
462462
``'r+'``
463463
It is similar to ``'a'``, but the file must already exist.
464464
complevel : int, 0-9, default None
465-
Specifies a compression level for data.
466-
A value of 0 or None disables compression.
465+
Specifies a compression level for data.
466+
A value of 0 or None disables compression.
467467
complib : {'zlib', 'lzo', 'bzip2', 'blosc'}, default 'zlib'
468-
Specifies the compression library to be used.
469-
As of v0.20.2 these additional compressors for Blosc are supported
470-
(default if no compressor specified: 'blosc:blosclz'):
471-
{'blosc:blosclz', 'blosc:lz4', 'blosc:lz4hc', 'blosc:snappy',
472-
'blosc:zlib', 'blosc:zstd'}.
473-
Specifying a compression library which is not available issues
474-
a ValueError.
468+
Specifies the compression library to be used.
469+
As of v0.20.2 these additional compressors for Blosc are supported
470+
(default if no compressor specified: 'blosc:blosclz'):
471+
{'blosc:blosclz', 'blosc:lz4', 'blosc:lz4hc', 'blosc:snappy',
472+
'blosc:zlib', 'blosc:zstd'}.
473+
Specifying a compression library which is not available issues
474+
a ValueError.
475475
fletcher32 : bool, default False
476-
If applying compression use the fletcher32 checksum
476+
If applying compression use the fletcher32 checksum.
477+
**kwargs
478+
These parameters will be passed to the PyTables open_file method.
477479
478480
Examples
479481
--------
@@ -482,6 +484,17 @@ class HDFStore:
482484
>>> store['foo'] = bar # write to HDF5
483485
>>> bar = store['foo'] # retrieve
484486
>>> store.close()
487+
488+
**Create or load HDF5 file in-memory**
489+
490+
When passing the `driver` option to the PyTables open_file method through
491+
**kwargs, the HDF5 file is loaded or created in-memory and will only be
492+
written when closed:
493+
494+
>>> bar = pd.DataFrame(np.random.randn(10, 4))
495+
>>> store = pd.HDFStore('test.h5', driver='H5FD_CORE')
496+
>>> store['foo'] = bar
497+
>>> store.close() # only now, data is written to disk
485498
"""
486499

487500
_handle: Optional["File"]
@@ -634,6 +647,8 @@ def open(self, mode: str = "a", **kwargs):
634647
----------
635648
mode : {'a', 'w', 'r', 'r+'}, default 'a'
636649
See HDFStore docstring or tables.open_file for info about modes
650+
**kwargs
651+
These parameters will be passed to the PyTables open_file method.
637652
"""
638653
tables = _tables()
639654

0 commit comments

Comments
 (0)