Skip to content

Commit da07446

Browse files
committed
Merge pull request #5499 from jreback/hdf_args
API/ENH: pass thru store creation arguments for HDFStore; can be used to support in-memory stores
2 parents 46008ec + 70d55cd commit da07446

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

doc/source/release.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ API Changes
289289
- ``flush`` now accepts an ``fsync`` parameter, which defaults to ``False``
290290
(:issue:`5364`)
291291
- ``unicode`` indices not supported on ``table`` formats (:issue:`5386`)
292+
- pass thru store creation arguments; can be used to support in-memory stores
292293
- ``JSON``
293294

294295
- added ``date_unit`` parameter to specify resolution of timestamps.

doc/source/v0.13.0.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ HDFStore API Changes
373373
- add the keyword ``dropna=True`` to ``append`` to change whether ALL nan rows are not written
374374
to the store (default is ``True``, ALL nan rows are NOT written), also settable
375375
via the option ``io.hdf.dropna_table`` (:issue:`4625`)
376+
- pass thru store creation arguments; can be used to support in-memory stores
376377

377378
Enhancements
378379
~~~~~~~~~~~~

pandas/io/pytables.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ def __init__(self, path, mode=None, complevel=None, complib=None,
376376
self._complib = complib
377377
self._fletcher32 = fletcher32
378378
self._filters = None
379-
self.open(mode=mode)
379+
self.open(mode=mode, **kwargs)
380380

381381
@property
382382
def root(self):
@@ -465,7 +465,7 @@ def items(self):
465465

466466
iteritems = items
467467

468-
def open(self, mode='a'):
468+
def open(self, mode='a', **kwargs):
469469
"""
470470
Open the file in the specified mode
471471
@@ -502,11 +502,11 @@ def open(self, mode='a'):
502502
fletcher32=self._fletcher32)
503503

504504
try:
505-
self._handle = tables.openFile(self._path, self._mode)
505+
self._handle = tables.openFile(self._path, self._mode, **kwargs)
506506
except (IOError) as e: # pragma: no cover
507507
if 'can not be written' in str(e):
508508
print('Opening %s in read-only mode' % self._path)
509-
self._handle = tables.openFile(self._path, 'r')
509+
self._handle = tables.openFile(self._path, 'r', **kwargs)
510510
else:
511511
raise
512512
except (Exception) as e:

pandas/io/tests/test_pytables.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,28 @@ def test_reopen_handle(self):
489489
store.close()
490490
self.assert_(not store.is_open)
491491

492+
def test_open_args(self):
493+
494+
with ensure_clean_path(self.path) as path:
495+
496+
df = tm.makeDataFrame()
497+
498+
# create an in memory store
499+
store = HDFStore(path,mode='a',driver='H5FD_CORE',driver_core_backing_store=0)
500+
store['df'] = df
501+
store.append('df2',df)
502+
503+
tm.assert_frame_equal(store['df'],df)
504+
tm.assert_frame_equal(store['df2'],df)
505+
506+
store.close()
507+
508+
# only supported on pytable >= 3.0.0
509+
if LooseVersion(tables.__version__) >= '3.0.0':
510+
511+
# the file should not have actually been written
512+
self.assert_(os.path.exists(path) is False)
513+
492514
def test_flush(self):
493515

494516
with ensure_clean_store(self.path) as store:

0 commit comments

Comments
 (0)