From 70d55cd885e8555b493c7f0dd7551536ad65977d Mon Sep 17 00:00:00 2001 From: jreback Date: Tue, 12 Nov 2013 12:24:02 -0500 Subject: [PATCH] API/ENH: pass thru store creation arguments for HDFStore; can be used to support in-memory stores --- doc/source/release.rst | 1 + doc/source/v0.13.0.txt | 1 + pandas/io/pytables.py | 8 ++++---- pandas/io/tests/test_pytables.py | 22 ++++++++++++++++++++++ 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/doc/source/release.rst b/doc/source/release.rst index 6ae7493fb4b72..17fe4be734f4d 100644 --- a/doc/source/release.rst +++ b/doc/source/release.rst @@ -289,6 +289,7 @@ API Changes - ``flush`` now accepts an ``fsync`` parameter, which defaults to ``False`` (:issue:`5364`) - ``unicode`` indices not supported on ``table`` formats (:issue:`5386`) + - pass thru store creation arguments; can be used to support in-memory stores - ``JSON`` - added ``date_unit`` parameter to specify resolution of timestamps. diff --git a/doc/source/v0.13.0.txt b/doc/source/v0.13.0.txt index 73800c06669f5..70fc0572ad8fb 100644 --- a/doc/source/v0.13.0.txt +++ b/doc/source/v0.13.0.txt @@ -373,6 +373,7 @@ HDFStore API Changes - add the keyword ``dropna=True`` to ``append`` to change whether ALL nan rows are not written to the store (default is ``True``, ALL nan rows are NOT written), also settable via the option ``io.hdf.dropna_table`` (:issue:`4625`) +- pass thru store creation arguments; can be used to support in-memory stores Enhancements ~~~~~~~~~~~~ diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index bc2f41502614d..49f60a7051ba9 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -376,7 +376,7 @@ def __init__(self, path, mode=None, complevel=None, complib=None, self._complib = complib self._fletcher32 = fletcher32 self._filters = None - self.open(mode=mode) + self.open(mode=mode, **kwargs) @property def root(self): @@ -465,7 +465,7 @@ def items(self): iteritems = items - def open(self, mode='a'): + def open(self, mode='a', **kwargs): """ Open the file in the specified mode @@ -502,11 +502,11 @@ def open(self, mode='a'): fletcher32=self._fletcher32) try: - self._handle = tables.openFile(self._path, self._mode) + self._handle = tables.openFile(self._path, self._mode, **kwargs) except (IOError) as e: # pragma: no cover if 'can not be written' in str(e): print('Opening %s in read-only mode' % self._path) - self._handle = tables.openFile(self._path, 'r') + self._handle = tables.openFile(self._path, 'r', **kwargs) else: raise except (Exception) as e: diff --git a/pandas/io/tests/test_pytables.py b/pandas/io/tests/test_pytables.py index 737acef209a50..759f63a962e57 100644 --- a/pandas/io/tests/test_pytables.py +++ b/pandas/io/tests/test_pytables.py @@ -489,6 +489,28 @@ def test_reopen_handle(self): store.close() self.assert_(not store.is_open) + def test_open_args(self): + + with ensure_clean_path(self.path) as path: + + df = tm.makeDataFrame() + + # create an in memory store + store = HDFStore(path,mode='a',driver='H5FD_CORE',driver_core_backing_store=0) + store['df'] = df + store.append('df2',df) + + tm.assert_frame_equal(store['df'],df) + tm.assert_frame_equal(store['df2'],df) + + store.close() + + # only supported on pytable >= 3.0.0 + if LooseVersion(tables.__version__) >= '3.0.0': + + # the file should not have actually been written + self.assert_(os.path.exists(path) is False) + def test_flush(self): with ensure_clean_store(self.path) as store: