From 59a7fa078a3f3d97ed3b20e0c958be41d95cc7b6 Mon Sep 17 00:00:00 2001 From: Kevin Sheppard Date: Fri, 12 Jun 2015 15:08:51 -0400 Subject: [PATCH] BUG: Check complib values Add check for complib when opening a HDFStore closes #4582 closes #8874 --- doc/source/whatsnew/v0.16.2.txt | 2 ++ pandas/io/pytables.py | 4 ++++ pandas/io/tests/test_pytables.py | 7 +++++++ 3 files changed, 13 insertions(+) diff --git a/doc/source/whatsnew/v0.16.2.txt b/doc/source/whatsnew/v0.16.2.txt index 8314c1cfff0dd..8d62fce0130b9 100644 --- a/doc/source/whatsnew/v0.16.2.txt +++ b/doc/source/whatsnew/v0.16.2.txt @@ -174,3 +174,5 @@ Bug Fixes - Bug in ``read_hdf`` where ``auto_close`` could not be passed (:issue:`9327`). - Bug in ``read_hdf`` where open stores could not be used (:issue:`10330`). + +- Bug in ``to_hdf`` and ``HDFStore`` which did not check that complib choices were valid (:issue:`4582`, :issue:`8874`). \ No newline at end of file diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index eca855a38d725..31f649c498c14 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -389,6 +389,10 @@ def __init__(self, path, mode=None, complevel=None, complib=None, except ImportError as ex: # pragma: no cover raise ImportError('HDFStore requires PyTables, "{ex}" problem importing'.format(ex=str(ex))) + if complib not in (None, 'blosc', 'bzip2', 'lzo', 'zlib'): + raise ValueError("complib only supports 'blosc', 'bzip2', lzo' " + "or 'zlib' compression.") + self._path = path if mode is None: mode = 'a' diff --git a/pandas/io/tests/test_pytables.py b/pandas/io/tests/test_pytables.py index 4fc24c4cd1870..6aaeb6652f2b6 100644 --- a/pandas/io/tests/test_pytables.py +++ b/pandas/io/tests/test_pytables.py @@ -4718,6 +4718,13 @@ def test_read_hdf_errors(self): with open(path, mode='r') as store: self.assertRaises(NotImplementedError, read_hdf, store, 'df') + def test_invalid_complib(self): + df = DataFrame(np.random.rand(4, 5), + index=list('abcd'), + columns=list('ABCDE')) + with ensure_clean_path(self.path) as path: + self.assertRaises(ValueError, df.to_hdf, path, 'df', complib='blosc:zlib') + def _test_sort(obj): if isinstance(obj, DataFrame): return obj.reindex(sorted(obj.index))