Repository navigation
Open
Labels
Description
In zarr-developers/zarr-python#435, I think I uncovered a bug in the LZMA compressor.
Minimal, reproducible code sample, a copy-pastable example if possible
import numpy as np
import lzma
from numcodecs import LZMA
filters = [dict(id=lzma.FILTER_DELTA, dist=4),
dict(id=lzma.FILTER_LZMA2, preset=1)]
compressor = LZMA(filters=filters)
data = np.zeros(4)
encoded = compressor.encode(data)
compressor.decode(encoded)raises
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-129-0aabeb1b1948> in <module>()
6 data = np.zeros(4)
7 encoded = compressor.encode(data)
----> 8 compressor.decode(encoded)
~/.conda/envs/geo_scipy/lib/python3.6/site-packages/numcodecs/lzma.py in decode(self, buf, out)
63
64 # do decompression
---> 65 dec = _lzma.decompress(buf, format=self.format, filters=self.filters)
66
67 # handle destination
~/.conda/envs/geo_scipy/lib/python3.6/lzma.py in decompress(data, format, memlimit, filters)
330 results = []
331 while True:
--> 332 decomp = LZMADecompressor(format, memlimit, filters)
333 try:
334 res = decomp.decompress(data)
ValueError: Cannot specify filters except with FORMAT_RAW
Problem description
This seems like a bug. If the options I specified for the compressor are somehow invalid, we should raise an error when the compressor is created, rather than encoding data that can't be decoded.
Version and installation information
Please provide the following:
- Value of
numcodecs.__version__: 0.6.3 - Version of Python interpreter: 3.6
- Operating system (Linux/Windows/Mac): Mac
- How NumCodecs was installed (e.g., "using pip into virtual environment", or "using conda"): conda-forge
Also, if you think it might be relevant, please provide the output from pip list or
conda list depending on which was used to install NumCodecs.
Activity
rabernat commentedon May 3, 2019
Seems like it can be fixed by just adding
format=lzma.FORMAT_RAWto the LZMA constructor.jakirkham commentedon May 3, 2019
Yeah, I think this limitation comes from Python itself.
We could do that. Alternatively we could construct
LZMACompressorandLZMADecompressorobjects in the constructor. That should raise these errors as well.