Skip to content

DELTA filter: on-disk NDArray with multi-byte items decodes wrongly when the shape has a partial edge chunk #740

Closed

Description

@Karol-G

Description

An NDArray compressed with the DELTA filter and stored on disk (urlpath=...)
does not round-trip when the array shape is not a multiple of the chunk shape
and the item size is larger than 1 byte. Reading it back with blosc2.open(...)[:]
returns wrong values in the partial edge chunk, without an error or warning.

  • The same array kept in memory round-trips exactly.
  • With a shape that is a multiple of the chunk shape, the on-disk array is exact.
  • With 1-byte items (uint8), the on-disk array is exact.
  • It happens with DELTA alone and with [DELTA, SHUFFLE] (default codec, and also LZ4HC clevel 5).

This is silent data corruption, so it may be worth a warning or an error until it is fixed.

Reproduction

import os
import tempfile

import blosc2
import numpy as np

print("blosc2", blosc2.__version__, "| c-blosc2", blosc2.blosclib_version, "| numpy", np.__version__)
rng = np.random.default_rng(0)
cparams = {"filters": [blosc2.Filter.DELTA]}

with tempfile.TemporaryDirectory() as d:
    path = os.path.join(d, "a.b2nd")
    for dtype in (np.uint8, np.int16, np.float32):
        for shape in ((64, 160, 160), (64, 160, 256)):  # chunks (64, 160, 128): partial edge chunk / exact fit
            a = rng.normal(0, 100, shape).astype(dtype)
            mem = blosc2.asarray(a, chunks=(64, 160, 128), blocks=(16, 64, 32), cparams=cparams)
            blosc2.asarray(a, chunks=(64, 160, 128), blocks=(16, 64, 32), cparams=cparams, urlpath=path, mode="w")
            disk = blosc2.open(path)[:]
            bad = disk.view(np.uint8) != a.view(np.uint8)
            print(f"{np.dtype(dtype).name:8s} shape={shape}  in-memory exact={np.array_equal(mem[:], a)}  "
                  f"on-disk exact={not bad.any()}  wrong bytes={int(bad.sum())}")

Output:

blosc2 4.14.1 | c-blosc2 3.3.5 ($Date:: 2026-09-24 #$) | numpy 2.5.4
uint8    shape=(64, 160, 160)  in-memory exact=True  on-disk exact=True  wrong bytes=0
uint8    shape=(64, 160, 256)  in-memory exact=True  on-disk exact=True  wrong bytes=0
int16    shape=(64, 160, 160)  in-memory exact=True  on-disk exact=False  wrong bytes=440873
int16    shape=(64, 160, 256)  in-memory exact=True  on-disk exact=True  wrong bytes=0
float32  shape=(64, 160, 160)  in-memory exact=True  on-disk exact=False  wrong bytes=1175413
float32  shape=(64, 160, 256)  in-memory exact=True  on-disk exact=True  wrong bytes=0

In the failing cases, all wrong values are in the second chunk along the last
axis, which covers only 32 of its 128 columns.

Expected behaviour

blosc2.open(path)[:] returns exactly the array that was written, as it does for
the in-memory array.

Environment

  • python-blosc2 4.14.1 (c-blosc2 3.3.5), numpy 2.5.4
  • Python 3.12.15, Linux 6.17 x86_64 (glibc 2.39)

Activity

  1. added a commit that references this issue on Oct 24, 2026
    a164a53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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