Skip to content

Can't pickle numcodecs codecs #744

Open
@TomNicholas

Description

@TomNicholas

Zarr version

3.0.6

Numcodecs version

0.16.0

Python Version

3.12.2

Operating System

Mac

Installation

conda

Description

The numcodecs codecs aren't pickleable.

For me it's a problem because I can't use AWS lambda functions with the lithops serverless framework. My understanding is that pickleability is something that zarr-python tests it can do, so it's inconsistent that numcodecs can't.

The problem seems to be this weird dynamic creation of codec classes. Presumably if numcodecs just defined these classes in a more conentional static way then they would be pickleable.

Steps to reproduce

In [1]: from numcodecs.zarr3 import Zlib

In [2]: import zarr

In [3]: arr = zarr.create_array(store={}, shape=(10, 10), dtype='f8', compressors=[Zlib()])
/Users/tom/miniconda3/envs/lithops-coiled/lib/python3.12/site-packages/numcodecs/zarr3.py:133: UserWarning: Numcodecs codecs are not in the Zarr version 3 specification and may not be supported by other zarr implementations.
  super().__init__(**codec_config)

In [4]: arr.info
Out[4]: 
Type               : Array
Zarr format        : 3
Data type          : DataType.float64
Shape              : (10, 10)
Chunk shape        : (10, 10)
Order              : C
Read-only          : False
Store type         : MemoryStore
Filters            : ()
Serializer         : BytesCodec(endian=<Endian.little: 'little'>)
Compressors        : (Zlib(codec_name='numcodecs.zlib', codec_config={}),)
No. bytes          : 800

In [5]: import pickle

In [6]: pickle.dumps(arr)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[6], line 1
----> 1 pickle.dumps(arr)

AttributeError: Can't pickle local object '_make_bytes_bytes_codec.<locals>._Codec'

Additional output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions