Skip to content

Delta nan handling #765

@slowjazz

Description

@slowjazz

The Delta filter does not always preserve the input if it contains nans. Is it possible to use np.nandiff and np.nancumsum in place of np.diff/np.cumsum in the implementation of Delta?

Example:

#!/usr/bin/env -S uv run --script
#
#
# /// script
# requires-python = ">=3.12"
# dependencies = ["numcodecs==0.16.1"]
# ///
#

import numpy as np
from numcodecs import Delta

codec = Delta(dtype=np.float64)

arr_in = np.array([1.0, 2.0, np.nan, 4.0, 5.0], dtype=np.float64)
arr_enc = codec.encode(arr_in)
arr_dec = codec.decode(arr_enc)

cmp = np.array_equal(arr_in, arr_dec, equal_nan=True)
print('input', arr_in)
print('output', arr_dec)
$ uv run example.py
input [ 1.  2. nan  4.  5.]
output [ 1.  2. nan nan nan]

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