-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
GH15943 Fixed defaults for compression in HDF5 #16355
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -736,6 +736,59 @@ def test_put_compression_blosc(self): | |
store.put('c', df, format='table', complib='blosc') | ||
tm.assert_frame_equal(store['c'], df) | ||
|
||
def test_complibs_default_settings(self): | ||
# GH15943 | ||
df = tm.makeDataFrame() | ||
|
||
# Set complevel and check if complib is automatically set to | ||
# default value | ||
with ensure_clean_path(self.path) as tmpfile: | ||
df.to_hdf(tmpfile, 'df', complevel=9) | ||
result = pd.read_hdf(tmpfile, 'df') | ||
tm.assert_frame_equal(result, df) | ||
|
||
with tables.open_file(tmpfile, mode='r') as h5file: | ||
for node in h5file.walk_nodes(where='/df', classname='Leaf'): | ||
assert node.filters.complevel == 9 | ||
assert node.filters.complib == 'zlib' | ||
|
||
# Set complib and check to see if compression is disabled | ||
with ensure_clean_path(self.path) as tmpfile: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this doesn't make sense. you are specifying a complib, yet no compression? again this is confusing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added the 3 cases where at least one of the parameters complib and complevel is missing. Setting complib and leaving complevel unset is one of those. I think these are good tests to see if the defaults behave as we discussed. I did not add tests to see what would happen if i set the parameters to illegal values, fx what happens if complevel is negative? I also added the testcase where i override the file-wide defaults. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add some tests for illegal values, though PyTables should actually validate these |
||
df.to_hdf(tmpfile, 'df', complib='zlib') | ||
result = pd.read_hdf(tmpfile, 'df') | ||
tm.assert_frame_equal(result, df) | ||
|
||
with tables.open_file(tmpfile, mode='r') as h5file: | ||
for node in h5file.walk_nodes(where='/df', classname='Leaf'): | ||
assert node.filters.complevel == 0 | ||
assert node.filters.complib is None | ||
|
||
# Check if not setting complib or complevel results in no compression | ||
with ensure_clean_path(self.path) as tmpfile: | ||
df.to_hdf(tmpfile, 'df') | ||
result = pd.read_hdf(tmpfile, 'df') | ||
tm.assert_frame_equal(result, df) | ||
|
||
with tables.open_file(tmpfile, mode='r') as h5file: | ||
for node in h5file.walk_nodes(where='/df', classname='Leaf'): | ||
assert node.filters.complevel == 0 | ||
assert node.filters.complib is None | ||
|
||
# Check if file-defaults can be overridden on a per table basis | ||
with ensure_clean_path(self.path) as tmpfile: | ||
store = pd.HDFStore(tmpfile) | ||
store.append('dfc', df, complevel=9, complib='blosc') | ||
store.append('df', df) | ||
store.close() | ||
|
||
with tables.open_file(tmpfile, mode='r') as h5file: | ||
for node in h5file.walk_nodes(where='/df', classname='Leaf'): | ||
assert node.filters.complevel == 0 | ||
assert node.filters.complib is None | ||
for node in h5file.walk_nodes(where='/dfc', classname='Leaf'): | ||
assert node.filters.complevel == 9 | ||
assert node.filters.complib == 'blosc' | ||
|
||
def test_complibs(self): | ||
# GH14478 | ||
df = tm.makeDataFrame() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think let's change the defaults to
complevel=None
,complib=None
.If then complevel is not None and > 0 you can set complib to zlib (if it not defined)
if complib is not None and complevel is not 0 then you set the filter.