Skip to content

Conversation

@tasansal
Copy link

@tasansal tasansal commented Dec 17, 2025

Fixes #812

With Zarr v3 and using zarr.codecs.ZFPY as serializer, the ZFP compressor logic in numcodecs complains that it is not F-order data. The chunk data neither C/F contiguous when it is a sliced view of an existing array. I traced it down to the logic here, and this PR addresses the issue.

if buf.flags.c_contiguous:
flatten = False
else:
raise ValueError(
"The zfp codec does not support F order arrays. "
f"Your arrays flags were {buf.flags}."
)
buf = ensure_contiguous_ndarray(buf, flatten=flatten)

By making the check more explicit and applying np.ascontiguous after ensuring it not F-order, the issue goes away.


Reproducer

import numpy as np
import asyncio
import zarr
from zarr.storage import MemoryStore
from zarr import create_array
from zarr.codecs import numcodecs

# fixed accuracy
zfp = numcodecs.ZFPY(mode=4, tolerance=0.001)
store = MemoryStore()

zfp_arr = create_array(
    store,
    shape=(100, 100, 100),
    chunks=(50, 50, 100),
    dtype="float32",
    serializer=zfp,
    compressors=None
)

rng = np.random.default_rng()
data = rng.random(zfp_arr.shape)
zfp_arr[:] = data

Raises:

ValueError: The zfp codec does not support F order arrays. Your arrays flags were   C_CONTIGUOUS : False
  F_CONTIGUOUS : False
  OWNDATA : False
  WRITEABLE : True
  ALIGNED : True
  WRITEBACKIFCOPY : False
.

If we look at the chunk slices' numpy flags:

>>> data[:50, :50, :].flags.c_contiguous
False
>>> data[:50, 50:, :].flags.c_contiguous
False
>>> data[50:, 50:, :].flags.c_contiguous
False
>>> data[50:, :50, :].flags.c_contiguous
False

TODO:

  • Unit tests and/or doctests in docstrings
  • Tests pass locally
  • Docstrings and API docs for any new/modified user-facing classes and functions
  • Changes documented in docs/release.rst
  • Docs build locally
  • GitHub Actions CI passes
  • Test coverage to 100% (Codecov passes)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ZFP with Zarr breaks when data is a view

1 participant