Skip to content

Commit 3cdd1df

Browse files
Kevin Sheppardjreback
Kevin Sheppard
authored andcommitted
BUG: Check complib values, #4582 and #8874
1 parent 7f14b28 commit 3cdd1df

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

doc/source/whatsnew/v0.16.2.txt

+4
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,8 @@ Bug Fixes
164164
- Bug in ``Panel.apply`` when the result has ndim = 0 (:issue:`10332`)
165165
- Bug in ``read_hdf`` where ``auto_close`` could not be passed (:issue:`9327`).
166166
- Bug in ``read_hdf`` where open stores could not be used (:issue:`10330`).
167+
167168
- Bug in adding empty ``DataFrame``s, now results in a ``DataFrame`` that ``.equals`` an empty ``DataFrame`` (:issue:`10181`).
169+
170+
171+
- 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)