Skip to content

Make all codecs pickleable #745

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

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

TomNicholas
Copy link
Member

@TomNicholas TomNicholas commented Apr 24, 2025

Attempt to fix #744, using the __init_subclass__ approach suggested by @d-v-b.

I think this approach seems promising, but currently tests fail, and I don't know why. I get errors like

    def get_codec(config):
        """Obtain a codec for the given configuration.
    
        Parameters
        ----------
        config : dict-like
            Configuration object.
    
        Returns
        -------
        codec : Codec
    
        Examples
        --------
    
        >>> import numcodecs as codecs
        >>> codec = codecs.get_codec(dict(id='zlib', level=1))
        >>> codec
        Zlib(level=1)
    
        """
        config = dict(config)
        codec_id = config.pop('id', None)
        cls = codec_registry.get(codec_id)
        if cls is None and codec_id in entries:
            logger.debug("Auto loading codec '%s' from entrypoint", codec_id)
            cls = entries[codec_id].load()
            register_codec(cls, codec_id=codec_id)
        if cls:
            return cls.from_config(config)
>       raise UnknownCodecError(f"{codec_id!r}")
E       numcodecs.errors.UnknownCodecError: codec not available: ''Blosc''

TODO:

  • Unit tests and/or doctests in docstrings
  • Tests pass locally
  • Changes documented in docs/release.rst
  • GitHub Actions CI passes
  • Test coverage to 100% (Codecov passes)

Comment on lines 305 to 307
print(codec)
print(codec.codec_name)
print(codec.__doc__)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for numcodecs.zarr3.Blosc this returns

Blosc(codec_name='numcodecs.Blosc', codec_config={})
numcodecs.Blosc

            See :class:`numcodecs.blosc.Blosc` for more details and parameters.
            

which all seems correct to me?

@@ -184,30 +195,18 @@ async def _encode_single(self, chunk_ndbuffer: NDBuffer, chunk_spec: ArraySpec)


def _add_docstring(cls: type[T], ref_class_name: str) -> type[T]:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All this can be deleted once the changes in this PR are applied to all the other codecs

Copy link

codecov bot commented Apr 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.96%. Comparing base (3438e16) to head (6d04f9b).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #745      +/-   ##
==========================================
- Coverage   99.96%   99.96%   -0.01%     
==========================================
  Files          63       63              
  Lines        2736     2708      -28     
==========================================
- Hits         2735     2707      -28     
  Misses          1        1              
Files with missing lines Coverage Δ
numcodecs/tests/test_zarr3.py 100.00% <100.00%> (ø)
numcodecs/zarr3.py 99.39% <100.00%> (-0.11%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

@chuckwondo chuckwondo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TomNicholas, I believe my suggested changes should get the tests to pass.

Co-authored-by: Chuck Daniels <[email protected]>
@TomNicholas
Copy link
Member Author

You legend @chuckwondo 🙇‍♂️

@TomNicholas
Copy link
Member Author

pre-commit.ci autofix

@@ -362,19 +286,39 @@ def evolve_from_array_spec(self, array_spec: ArraySpec) -> AsType:


# bytes-to-bytes checksum codecs
CRC32 = _add_docstring(_make_checksum_codec("crc32", "CRC32"), "numcodecs.checksum32.CRC32")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These codecs break the pattern of the ones above because they have "numcodecs.checksum32.<name>" instead of "numcodecs.<lowercasename>.<name>". I ignored that, but it doesn't seem to matter whatsoever?? Suspicious.

@TomNicholas TomNicholas marked this pull request as ready for review April 24, 2025 23:35
@TomNicholas
Copy link
Member Author

@d-v-b @jakirkham this is ready for review. It would be nice to release it quickly if possible 😁

Comment on lines +9 to +10
import numcodecs.bitround

Copy link
Member Author

@TomNicholas TomNicholas Apr 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember adding this - maybe the linter did??

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

Successfully merging this pull request may close these issues.

Can't pickle numcodecs codecs
2 participants