Skip to content

pytest.approx abs/rel logic seems to be flipped on np.array() #3695

@abrammer

Description

@abrammer

Hopefully, I'm not missing something obvious here.

Absolute and relative tolerance arguments or logic seem to get flipped when the comparison is against a np.array

Think I've tracked it down to this line.

return ApproxNumpy(actual, self.abs, self.rel, self.nan_ok) == self.expected

abs and rel arguments should be in the other order according to the ApproxBase.__init__
def __init__(self, expected, rel=None, abs=None, nan_ok=False):

pytest.__version__
'3.6.3'
np.__version__
'1.13.1'
abs_check = pytest.approx(100, abs=0.1, rel=0)
rel_check = pytest.approx(100, abs=0, rel=0.1)
99 == abs_check
# False
np.array(99) == abs_check
# True

99 == rel_check
# True
np.array(99) == rel_check
# False

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions