Skip to content

Unexpected dependence on chunks with JSON and MsgPack codecs #258

@jeromekelleher

Description

@jeromekelleher
    import numcodecs
    import zarr
    z = zarr.empty(1, dtype=object, object_codec=numcodecs.JSON(), chunks=(1,))
    z[0] = ["11"]
    print(z[:])
    z[0] = ["11", "1"]
    print(z[:]) # Borks

gives

['11']
Traceback (most recent call last):
  File "dev.py", line 204, in <module>
    print(z[:])
  File "/home/jk/.local/lib/python3.5/site-packages/zarr/core.py", line 555, in __getitem__
    return self.get_basic_selection(selection, fields=fields)
  File "/home/jk/.local/lib/python3.5/site-packages/zarr/core.py", line 681, in get_basic_selection
    fields=fields)
  File "/home/jk/.local/lib/python3.5/site-packages/zarr/core.py", line 723, in _get_basic_selection_nd
    return self._get_selection(indexer=indexer, out=out, fields=fields)
  File "/home/jk/.local/lib/python3.5/site-packages/zarr/core.py", line 1011, in _get_selection
    drop_axes=indexer.drop_axes, fields=fields)
  File "/home/jk/.local/lib/python3.5/site-packages/zarr/core.py", line 1604, in _chunk_getitem
    chunk = self._decode_chunk(cdata)
  File "/home/jk/.local/lib/python3.5/site-packages/zarr/core.py", line 1747, in _decode_chunk
    chunk = chunk.reshape(self._chunks, order=self._order)
ValueError: cannot reshape array of size 2 into shape (1,)

Problem description

When using the JSON on MsgPack codecs to store an array of lists of strings, I get the above weird behaviour. It's easiest to just play around with the snippet above and try out different things, as it's tricky to explain what's happening. Basically though, it seems that this code path is sensitive to the chunk size in a way that others aren't --- typically, the library is perfectly happy with any chunk size.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions