keras-team/keras · error · ValueError

Unsupported `.npy` file version: {version}.

Error message

Unsupported `.npy` file version: {version}.

What it means

Error "Unsupported `.npy` file version: {version}." thrown in keras-team/keras.

Source

Thrown at keras/src/datasets/npz_utils.py:67

    """
    try:
        # Fast path: numeric arrays load with pickle fully disabled.
        return np.lib.format.read_array(fp, allow_pickle=False)
    except ValueError:
        # Object array: rewind, skip the header, then restrict the unpickler.
        fp.seek(0)
        version = np.lib.format.read_magic(fp)
        if version[0] == 1:
            np.lib.format.read_array_header_1_0(fp)
        elif version[0] in (2, 3):
            # numpy exposes no public `read_array_header_3_0`. The 3.0 format
            # only differs from 2.0 by encoding the header string as UTF-8
            # instead of latin1; the 4-byte header-length layout we skip past
            # to reach the pickle stream is identical, so 2.0's reader handles
            # both.
            np.lib.format.read_array_header_2_0(fp)
        else:
            raise ValueError(f"Unsupported `.npy` file version: {version}.")
        return RestrictedUnpickler(fp).load()


def load_npz(path):
    """Safely load an `.npz` archive into a `dict` of arrays.

    This is a drop-in replacement for `np.load(path, allow_pickle=True)` for
    the built-in datasets that store ragged object arrays. Unlike
    `allow_pickle=True`, it only ever unpickles numpy arrays, so loading a
    maliciously crafted file cannot execute arbitrary code.

    Args:
        path: Path to the `.npz` file.

    Returns:
        A `dict` mapping each member name to its array.
    """
    arrays = {}

View on GitHub (pinned to 7a34a03db6)

When it happens

Trigger: Thrown at keras/src/datasets/npz_utils.py:67 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25). Data as JSON: /api/errors/5aad9894d290c9a6. Report an issue: GitHub.