Skip to content
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

bug in v2 codec pipeline #2501

Open
dcherian opened this issue Nov 18, 2024 · 3 comments · May be fixed by #2515
Open

bug in v2 codec pipeline #2501

dcherian opened this issue Nov 18, 2024 · 3 comments · May be fixed by #2515
Assignees
Labels
bug Potential issues with the zarr-python library

Comments

@dcherian
Copy link
Contributor

dcherian commented Nov 18, 2024

Zarr version

main

Description

There is a bug in these lines:

cdata is not of type bytes in the else clause:

# compress
if self.compressor:
cdata = await asyncio.to_thread(self.compressor.encode, chunk)
else:
cdata = chunk
return chunk_spec.prototype.buffer.from_bytes(cdata)

cc @normanrz

Steps to reproduce

This is triggering failures in xarray's test suite. I haven't succeeded at making a minimal reproducer.

Additional output

No response

@dcherian dcherian added the bug Potential issues with the zarr-python library label Nov 18, 2024
@dcherian
Copy link
Contributor Author

Ah this occurs when self.filters is None and self.compressor is None

@normanrz
Copy link
Contributor

I just tried to reproduce this with

>>> import zarr
>>> import numpy as np
>>> a = zarr.Array.create("test.zarr", shape=(12,12,12), chunks=(12,12,12), dtype="uint8", zarr_format=2)
>>> a
<Array file://test.zarr shape=(12, 12, 12) dtype=uint8>
>>> str(a.metadata.filters)
'None'
>>> str(a.metadata.compressor)
'None'
>>> a[:] = np.ones((12,12,12))
>>> a[:]
array([[[1, 1, 1, ..., 1, 1, 1], ...

This seems to have worked.

@dcherian
Copy link
Contributor Author

dcherian commented Nov 22, 2024

Here you go . When you set using a slice of a different array, it's not C-contiguous

import numpy as np
import zarr
from zarr.storage import MemoryStore

a = zarr.Array.create(MemoryStore({}), shape=(10,8), chunks=(3,3), fill_value=np.nan, dtype="float64", zarr_format=2, exists_ok=True)
print(a.metadata)
array = np.ones(a.shape)
a[slice(6, 9, None), slice(3, 6, None)] = array[slice(6, 9, None), slice(3, 6, None)]  # The slice on the RHS is important
# ValueError: ndarray is not C-contiguous

@normanrz normanrz self-assigned this Nov 22, 2024
normanrz added a commit that referenced this issue Nov 24, 2024
@normanrz normanrz linked a pull request Nov 24, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Potential issues with the zarr-python library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants