Skip to content

sharding codec use of lru caching fails with numpy void scalars #3054

Closed

Description

@d-v-b

numpy void scalars are not hashable, which means that a class with a np.void attribute cannot be hashed by lru_cache, which is used by the sharding codec class here.

I ran into this In #2874. Any ideas for fixing this would be appreciated! IMO the ideal fix would be to resolve the basic performance problems we are solving with this caching layer.

Activity

  1. nenb commented on May 19, 2025

    @nenb

    It seems like _get_chunk_spec (the problem function) is internal to the module in question, and is only called a handful of times. Might a practical solution (short-term) be to add another function that parses the inputs to _get_chunk_spec prior to calling it? This parser could then check for a void scalar, convert it to something hashable (e.g. (dtype signature, raw bytes), and then recover the original value from the hashable object prior to returning from _get_chunk_spec.

    I agree that the ideal fix (likely requires larger refactor, longer-term) would to resolve the basic performance problems that are being solved with this caching layer.

  2. added
    bugPotential issues with the zarr-python library
    on Apr 23, 2026
  3. sehoffmann commented on Jul 20, 2026

    @sehoffmann
    Contributor

    +1 Also ran across this when trying to do sharding on arrays with structured dtypes (as they have np.void type fill values)

  4. sehoffmann commented on Jul 20, 2026

    @sehoffmann
    Contributor

    In my case, the issue is the default ArraySpec.__hash__ implementation which hashes each field, including np.void fill values. I think this can be fixed locally in ArraySpec by manually hashing np.void fill values based on their byte content (.tobytes()). If such np.void values need to be hashed in different places as well, it might make sense to introduce a dedicated utility function for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugPotential issues with the zarr-python library

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions