Skip to content

Run-Length Encoding input is not properly supported by RectilinearChunkGrid #3946

@maxrjones

Description

@maxrjones

Zarr version

v3.2.0

Numcodecs version

v0.16.5

Python Version

3.12

Operating System

Mac

Installation

PyPI via a uv venv

Description

@jhamman's forthcoming blog post included this as an expected supported input, but it doesn't work.

I would expect the below to at least raise a more informative error, instead I get:

  File "/Users/max/Documents/Code/maxrjones/test-scripts/test-zarr/test-zarr-blog1.py", line 14, in <module>
    arr = zarr.create_array(
          ^^^^^^^^^^^^^^^^^^
  File "/Users/max/.cache/uv/environments-v2/test-zarr-blog1-041a0d706b93a99a/lib/python3.12/site-packages/zarr/api/synchronous.py", line 948, in create_array
    sync(
  File "/Users/max/.cache/uv/environments-v2/test-zarr-blog1-041a0d706b93a99a/lib/python3.12/site-packages/zarr/core/sync.py", line 158, in sync
    raise return_result
  File "/Users/max/.cache/uv/environments-v2/test-zarr-blog1-041a0d706b93a99a/lib/python3.12/site-packages/zarr/core/sync.py", line 118, in _runner
    return await coro
           ^^^^^^^^^^
  File "/Users/max/.cache/uv/environments-v2/test-zarr-blog1-041a0d706b93a99a/lib/python3.12/site-packages/zarr/core/array.py", line 4715, in create_array
    return await init_array(
           ^^^^^^^^^^^^^^^^^
  File "/Users/max/.cache/uv/environments-v2/test-zarr-blog1-041a0d706b93a99a/lib/python3.12/site-packages/zarr/core/array.py", line 4415, in init_array
    rectilinear_meta = RectilinearChunkGridMetadata(
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<string>", line 4, in __init__
  File "/Users/max/.cache/uv/environments-v2/test-zarr-blog1-041a0d706b93a99a/lib/python3.12/site-packages/zarr/core/metadata/v3.py", line 299, in __post_init__
    object.__setattr__(self, "chunk_shapes", _validate_chunk_shapes(self.chunk_shapes))
                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/max/.cache/uv/environments-v2/test-zarr-blog1-041a0d706b93a99a/lib/python3.12/site-packages/zarr/core/metadata/v3.py", line 231, in _validate_chunk_shapes
    bad = [i for i, e in enumerate(edges) if e < 1]
                                             ^^^^^
TypeError: '<' not supported between instances of 'list' and 'int'

Steps to reproduce

# /// script
# dependencies = [
#   "zarr==3.2.0",
#   "numpy",
#   "obstore",
# ]
# ///

import zarr
print(zarr.print_debug_info())
zarr.config.set({"array.rectilinear_chunks": True})
store = zarr.storage.MemoryStore()
# Create an array where chunks along the second axis vary in size
arr = zarr.create_array(
store=store,
shape=(10, 10),
chunks = [[6, 4], [[3, 3], 1]],
dtype="i4",
zarr_format=3,
)
arr[:] = 1
print(arr.write_chunk_sizes)
print(arr.read_chunk_sizes)

Additional output

No response

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