Skip to content

Commit 59a7fa0

Browse files
author
Kevin Sheppard
committed
BUG: Check complib values
Add check for complib when opening a HDFStore closes pandas-dev#4582 closes pandas-dev#8874
1 parent 51047d4 commit 59a7fa0

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

doc/source/whatsnew/v0.16.2.txt

+2
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,5 @@ Bug Fixes
174174

175175
- Bug in ``read_hdf`` where ``auto_close`` could not be passed (:issue:`9327`).
176176
- Bug in ``read_hdf`` where open stores could not be used (:issue:`10330`).
177+
178+
- Bug in ``to_hdf`` and ``HDFStore`` which did not check that complib choices were valid (:issue:`4582`, :issue:`8874`).

pandas/io/pytables.py

+4
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,10 @@ def __init__(self, path, mode=None, complevel=None, complib=None,
389389
except ImportError as ex: # pragma: no cover
390390
raise ImportError('HDFStore requires PyTables, "{ex}" problem importing'.format(ex=str(ex)))
391391

392+
if complib not in (None, 'blosc', 'bzip2', 'lzo', 'zlib'):
393+
raise ValueError("complib only supports 'blosc', 'bzip2', lzo' "
394+
"or 'zlib' compression.")
395+
392396
self._path = path
393397
if mode is None:
394398
mode = 'a'

pandas/io/tests/test_pytables.py

+7
Original file line numberDiff line numberDiff line change
@@ -4718,6 +4718,13 @@ def test_read_hdf_errors(self):
47184718
with open(path, mode='r') as store:
47194719
self.assertRaises(NotImplementedError, read_hdf, store, 'df')
47204720

4721+
def test_invalid_complib(self):
4722+
df = DataFrame(np.random.rand(4, 5),
4723+
index=list('abcd'),
4724+
columns=list('ABCDE'))
4725+
with ensure_clean_path(self.path) as path:
4726+
self.assertRaises(ValueError, df.to_hdf, path, 'df', complib='blosc:zlib')
4727+
47214728
def _test_sort(obj):
47224729
if isinstance(obj, DataFrame):
47234730
return obj.reindex(sorted(obj.index))

0 commit comments

Comments
 (0)