-
Notifications
You must be signed in to change notification settings - Fork 25
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
Compatibility with Zarr 3 #123
Comments
I actually realized the migration guide doesn't mention |
Sorry, Fedora was a bit behind on releases; I've re-built with the latest version https://copr.fedorainfracloud.org/coprs/qulogic/zarr3/build/8547624/ There are only 97 failures in that case, but still of the same style. |
I am aware of the issue. Technically it is that Zarr 3 that no longer supports numcodecs. Imagecodecs itself does not use zarr anywhere (except for testing) and does not claim to support zarr 3: imagecodecs/imagecodecs/imagecodecs.py Line 36 in 988af50
imagecodecs/imagecodecs/imagecodecs.py Lines 85 to 86 in 988af50
Line 766 in 988af50
Zarr 3 codecs are much more complicated than numcodecs codecs. They include multi-class inheritance, mixins, dataclasses, async, type hints, partial reads, and whatnot. It's going to be a major task to implement and test zarr 3 compatible codecs for all 64 imagecodecs codecs. |
I'm aware; this is a preliminary check before doing any updating.
It appears that this is not specifically Zarr 3, but Zarr file format 3. If you pass |
I believe this is a bug in Zarr, as in zarr-developers/zarr-python#2735. If I patch in the correct signedness, then I'm down to 9 test failures of |
I might have misunderstood this issue: is the objective merely getting the imagecodecs tests to pass with Zarr 3 installed? Or to support Zarr 3, that is (for me at least) provide Zarr format 3 compatible codecs? |
These are the remaining test failures with patched test_imagecodecs.py and patched zarr 3.0.1:
The |
The test failures and hangs with patched Zarr 3 are fixed by: diff --git a/imagecodecs/numcodecs.py b/imagecodecs/numcodecs.py
index 8113337..4cfb0cc 100644
--- a/imagecodecs/numcodecs.py
+++ b/imagecodecs/numcodecs.py
@@ -414,8 +480,7 @@ class Byteshuffle(Codec):
).tobytes()
def decode(self, buf, out=None):
- if not isinstance(buf, numpy.ndarray):
- buf = numpy.frombuffer(buf, dtype=self.dtype).reshape(*self.shape)
+ buf = numpy.frombuffer(buf, dtype=self.dtype).reshape(*self.shape)
return imagecodecs.byteshuffle_decode(
buf,
axis=self.axis,
@@ -770,8 +835,7 @@ class Floatpred(Codec):
).tobytes()
def decode(self, buf, out=None):
- if not isinstance(buf, numpy.ndarray):
- buf = numpy.frombuffer(buf, dtype=self.dtype).reshape(*self.shape)
+ buf = numpy.frombuffer(buf, dtype=self.dtype).reshape(*self.shape)
return imagecodecs.floatpred_decode(
buf, axis=self.axis, dist=self.dist, out=out
)
diff --git a/imagecodecs/_bz2.pyx b/imagecodecs/_bz2.pyx
index 5f1ba07..3d142af 100644
--- a/imagecodecs/_bz2.pyx
+++ b/imagecodecs/_bz2.pyx
@@ -101,7 +101,7 @@ def bz2_encode(data, level=None, out=None):
if out is None and dstsize < 0:
# use Python's bz2 module
import bz2
- return bz2.compress(data, compresslevel)
+ return bz2.compress(bytes(data), compresslevel)
if out is None:
if dstsize < 0:
@@ -158,7 +158,7 @@ def bz2_decode(data, out=None):
# use Python's bz2 module
import bz2
- return bz2.decompress(data)
+ return bz2.decompress(bytes(data))
if out is None:
if dstsize < 0:
diff --git a/imagecodecs/_pglz.pyx b/imagecodecs/_pglz.pyx
index fef8d01..a2c4ddf 100644
--- a/imagecodecs/_pglz.pyx
+++ b/imagecodecs/_pglz.pyx
@@ -120,13 +120,14 @@ def pglz_encode(
if dstsize < PGLZ_MAX_OUTPUT(srcsize):
raise ValueError('output too small')
- with nogil:
- ret = pglz_compress(
- <const char*> &src[0],
- <int32> srcsize,
- <char*> &dst[offset],
- pglz_strategy
- )
+ # pglz_compress is not thread-safe
+ # with nogil:
+ ret = pglz_compress(
+ <const char*> &src[0],
+ <int32> srcsize,
+ <char*> &dst[offset],
+ pglz_strategy
+ )
if header:
pdst = <uint8_t*> &dst[0]
pdst[0] = srcsize & 255
diff --git a/tests/test_imagecodecs.py b/tests/test_imagecodecs.py
index cc786c5..dcc1354 100644
--- a/tests/test_imagecodecs.py
+++ b/tests/test_imagecodecs.py
@@ -5277,7 +5280,11 @@ def test_numcodecs(codec, photometric):
fname = f'test_{codec}.{photometric}.{data.dtype.str[1:]}.zarr.zip'
store = zarr.ZipStore(fname, mode='w')
else:
- store = zarr.MemoryStore()
+ try:
+ store = zarr.MemoryStore()
+ except AttributeError:
+ # zarr 3
+ store = zarr.storage.MemoryStore()
z = zarr.create(
store=store,
overwrite=True,
@@ -5285,6 +5292,7 @@ def test_numcodecs(codec, photometric):
chunks=chunks,
dtype=data.dtype.str,
compressor=compressor,
+ zarr_format=2,
)
z[:] = data
del z
|
The imagecodecs doctests fail with Zarr 3 due to tifffile's Zarr stores not being compatible (but that's an entirely other issue). |
I only meant Zarr 3 the library, not Zarr 3 the file format. Sorry if that was unclear.
I've made roughly the same changes, and it's good to see that that full test suite is not that far off from what Fedora runs. The only one I didn't see was the
And this one I didn't see; I suppose that Fedora doesn't run doctests. |
Sure. Thank you. |
Don't worry. It's just to make sure the examples are actually executable: imagecodecs/imagecodecs/imagecodecs.py Lines 360 to 467 in 988af50
|
This has now been fixed in the development version, except where Zarr provides int8 arrays as "buffer" contrary to Python/Cython norms of uint8. |
I've run a test build with Zarr 3, which fails 168 tests.
All of them appear to be variations of:
See https://zarr.readthedocs.io/en/latest/user-guide/v3_migration.html for further details.
The text was updated successfully, but these errors were encountered: