Skip to content
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

LZMA custom filter error #188

Open
rabernat opened this issue May 3, 2019 · 2 comments
Open

LZMA custom filter error #188

rabernat opened this issue May 3, 2019 · 2 comments
Labels

Comments

@rabernat
Copy link
Contributor

rabernat commented May 3, 2019

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.

@rabernat
Copy link
Contributor Author

rabernat commented May 3, 2019

Seems like it can be fixed by just adding format=lzma.FORMAT_RAW to the LZMA constructor.

@jakirkham
Copy link
Member

Yeah, I think this limitation comes from Python itself.

We could do that. Alternatively we could construct LZMACompressor and LZMADecompressor objects in the constructor. That should raise these errors as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants