|
3 | 3 | import numpy as np
|
4 | 4 | import pytest
|
5 | 5 |
|
6 |
| -from pandas.compat import is_platform_little_endian |
| 6 | +from pandas.compat import ( |
| 7 | + PY311, |
| 8 | + is_ci_environment, |
| 9 | + is_platform_linux, |
| 10 | + is_platform_little_endian, |
| 11 | +) |
7 | 12 | from pandas.errors import (
|
8 | 13 | ClosedFileError,
|
9 | 14 | PossibleDataLossError,
|
@@ -222,39 +227,44 @@ def test_complibs_default_settings_override(tmp_path, setup_path):
|
222 | 227 | assert node.filters.complib == "blosc"
|
223 | 228 |
|
224 | 229 |
|
225 |
| -def test_complibs(tmp_path, setup_path): |
| 230 | +@pytest.mark.parametrize("lvl", range(10)) |
| 231 | +@pytest.mark.parametrize("lib", tables.filters.all_complibs) |
| 232 | +@pytest.mark.filterwarnings("ignore:object name is not a valid") |
| 233 | +@pytest.mark.xfail( |
| 234 | + not PY311 and is_ci_environment() and is_platform_linux(), |
| 235 | + reason="producing invalid start bytes", |
| 236 | + raises=UnicodeDecodeError, |
| 237 | + strict=False, |
| 238 | +) |
| 239 | +def test_complibs(tmp_path, lvl, lib): |
226 | 240 | # GH14478
|
227 |
| - df = tm.makeDataFrame() |
| 241 | + df = DataFrame( |
| 242 | + np.ones((30, 4)), columns=list("ABCD"), index=np.arange(30).astype(np.str_) |
| 243 | + ) |
228 | 244 |
|
229 |
| - # Building list of all complibs and complevels tuples |
230 |
| - all_complibs = tables.filters.all_complibs |
231 | 245 | # Remove lzo if its not available on this platform
|
232 | 246 | if not tables.which_lib_version("lzo"):
|
233 |
| - all_complibs.remove("lzo") |
| 247 | + pytest.skip("lzo not available") |
234 | 248 | # Remove bzip2 if its not available on this platform
|
235 | 249 | if not tables.which_lib_version("bzip2"):
|
236 |
| - all_complibs.remove("bzip2") |
| 250 | + pytest.skip("bzip2 not available") |
237 | 251 |
|
238 |
| - all_levels = range(0, 10) |
239 |
| - all_tests = [(lib, lvl) for lib in all_complibs for lvl in all_levels] |
| 252 | + tmpfile = tmp_path / f"{lvl}_{lib}.h5" |
| 253 | + gname = f"{lvl}_{lib}" |
240 | 254 |
|
241 |
| - for lib, lvl in all_tests: |
242 |
| - tmpfile = tmp_path / setup_path |
243 |
| - gname = "foo" |
244 |
| - |
245 |
| - # Write and read file to see if data is consistent |
246 |
| - df.to_hdf(tmpfile, gname, complib=lib, complevel=lvl) |
247 |
| - result = read_hdf(tmpfile, gname) |
248 |
| - tm.assert_frame_equal(result, df) |
| 255 | + # Write and read file to see if data is consistent |
| 256 | + df.to_hdf(tmpfile, gname, complib=lib, complevel=lvl) |
| 257 | + result = read_hdf(tmpfile, gname) |
| 258 | + tm.assert_frame_equal(result, df) |
249 | 259 |
|
250 |
| - # Open file and check metadata for correct amount of compression |
251 |
| - with tables.open_file(tmpfile, mode="r") as h5table: |
252 |
| - for node in h5table.walk_nodes(where="/" + gname, classname="Leaf"): |
253 |
| - assert node.filters.complevel == lvl |
254 |
| - if lvl == 0: |
255 |
| - assert node.filters.complib is None |
256 |
| - else: |
257 |
| - assert node.filters.complib == lib |
| 260 | + # Open file and check metadata for correct amount of compression |
| 261 | + with tables.open_file(tmpfile, mode="r") as h5table: |
| 262 | + for node in h5table.walk_nodes(where="/" + gname, classname="Leaf"): |
| 263 | + assert node.filters.complevel == lvl |
| 264 | + if lvl == 0: |
| 265 | + assert node.filters.complib is None |
| 266 | + else: |
| 267 | + assert node.filters.complib == lib |
258 | 268 |
|
259 | 269 |
|
260 | 270 | @pytest.mark.skipif(
|
|
0 commit comments