Skip to content

Properly perform floating point comparisons for structs and lists #8

@MariusMerkleQC

Description

In lists and structs, nested floats are compared via exact equality. Instead, we should correctly use atol and rtol to compare these floats.

For 1-dimensional arrays, we could solve it like this:

        elif isinstance(dtype_left, pl.Array) and isinstance(dtype_right, pl.Array):
            # For two arrays, we necessarily need to have the same shape. If that isn't
            # the case, we cannot observe equality
            if dtype_left.shape != dtype_right.shape:
                return pl.repeat(pl.lit(False), pl.len())

            if len(dtype_left.shape) > 1:
                pass  # Multi-dimensional arrays not supported yet, but easy in practice

            breakpoint()
            return pl.all_horizontal(
                [
                    _compare_columns(
                        col_left=col_left.arr.get(i),
                        col_right=col_right.arr.get(i),
                        dtype_left=dtype_left.inner,
                        dtype_right=dtype_right.inner,
                        abs_tol=abs_tol,
                        rel_tol=rel_tol,
                        abs_tol_temporal=abs_tol_temporal,
                    )
                    for i in range(dtype_left.shape[0])
                ]
            )

The same idea (at least naively) should extend to lists. We would first compute the length of the largest list, and then iterate with list.get(idx, null_on_oob=True). This isn't great if there are many short lists and few long lists, but it could be a start.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions