Skip to content

allclose() vector atol parameter wrong shape if NaN in a or b. #14320

@pavelkomarov

Description

@pavelkomarov
>>>np.allclose([1,2,float('nan')], [1,2,float('nan')], equal_nan=True)
True
>>>np.allclose([1,2,float('nan')], [1,2,float('nan')], atol=[1,1], equal_nan=True)
True
>>>np.allclose([1,2,3], [1,2,3)], atol=[1,1,1], equal_nan=True)
True
>>>np.allclose([1,2,float('nan')], [1,2,float('nan')], atol=[1,1,1], equal_nan=True)
ValueError: operands could not be broadcast together with shapes (3,) (2,)

It appears that allclose is basically removing entries where a or b is NaN before passing them on to isclose with the same atol provided to allclose. This of course doesn't work if I expect there to be no NaNs some of the time and need to provide a longer atol because my a and b are different scales in different positions.

What should happen is allclose removes the same positions from atol before passing it on, so the dimensions always agree.

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