Repository navigation
Fail clearly on MS-Numpress arrays when pynumpress is missing - #225
Merged
levitsky merged 1 commit intoOct 26, 2026
Merged
Conversation
Without pynumpress the numpress compression terms were not in the compression map, so the array was decoded as if it were uncompressed. Depending on the encoded length that either raised 'buffer size must be a multiple of element size' or silently returned garbage values (NaN, 1e-312, ...). Register the six terms with a decoder that raises PyteomicsError naming pynumpress.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pynumpress is optional, and neither
pip install pyteomicsnor packages that depend on pyteomics (matchms, for example) install it. Without it, pyteomics 5.0.1 reads a numpress-encoded array as if it were uncompressed:When the encoded length is not a multiple of the dtype size, you get
ValueError: buffer size must be a multiple of element sizeinstead. All five real numpress files I tried (msconvert and OpenMS outputs) raise that error, which does not mention pynumpress.Why: the numpress names are only added to
_default_compression_mapwhen pynumpress imports. Without it,_determine_compressionfinds no known compression term,_decompressgetsNone, and it returns the raw bytes unchanged.Fix: when pynumpress is missing, still register the six numpress terms, mapped to a decoder that raises
PyteomicsError("Decoding '<term>' requirespynumpress."). Nothing changes when pynumpress is installed. #198 uses the same pattern for the zstd codecs.Tested:
test_numpress_without_pynumpressruns in a subprocess withsys.modules['pynumpress'] = Noneand checks that all six terms raise PyteomicsError. It fails on master (TypeError: 'NoneType' object is not callable) and passes with the fix.tests/test_*.pyexcepttest_usiandtest_unimod, which need the network): 467 passed, 10 failed before. 468 passed, 10 failed after. The 10 failures are the same both times: the process-basedmap()tests fail withOSError: [Errno 22]in my sandbox.Side note for the maintainers, not part of this PR: in draft #198, the "MS-Numpress linear prediction compression followed by zstd compression" entry is mapped to
_zlibNumpress(...)instead of_zstdNumpress(...).