Skip to content

BUG: Check complib values #10341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v0.16.2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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`).
4 changes: 4 additions & 0 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should iterrogate the PyTables/Filters class, as more things seem to be valid http://www.pytables.org/usersguide/libref/helper_classes.html#filtersclassdescr

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but then reading over the old issue. I am not sure these blosc compressors work (though not entirely sure why)

raise ValueError("complib only supports 'blosc', 'bzip2', lzo' "
"or 'zlib' compression.")

self._path = path
if mode is None:
mode = 'a'
Expand Down
7 changes: 7 additions & 0 deletions pandas/io/tests/test_pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down