Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pytest.approx gives wrong result when compared with numpy types #3449

Closed
nosarthur opened this issue May 4, 2018 · 4 comments
Closed

pytest.approx gives wrong result when compared with numpy types #3449

nosarthur opened this issue May 4, 2018 · 4 comments
Labels
status: needs information reporter needs to provide more information; can be closed after 2 or more weeks of inactivity

Comments

@nosarthur
Copy link

nosarthur commented May 4, 2018

In [18]: import pytest, numpy

In [19]: pytest.__version__
Out[19]: '3.5.1'

In [20]: numpy.__version__
Out[20]: '1.12.0'

In [21]: a = numpy.float64(3e-9)

In [22]: a == pytest.approx(0, abs=1e-7)
Out[22]: False

In [23]: float(a) == pytest.approx(0, abs=1e-7)
Out[23]: True

With pytest version 3.4.1, numpy 1.12.0, pytest.approx has the correct behavior

@pytestbot pytestbot added the status: help wanted developers would like help from experts on this topic label May 4, 2018
@mghicho
Copy link

mghicho commented May 4, 2018

Here is what I got, my numpy is 1.14.2 though.

Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pytest, numpy
>>> pytest.__version__
'3.5.1'
>>> numpy.__version__
'1.14.2'
>>> a = numpy.float64(3e-9)
>>> a == pytest.approx(0, abs=1e-7)
True
>>> float(a) == pytest.approx(0, abs=1e-7)
True
>>>

@nosarthur
Copy link
Author

I tried pytest 3.5.1 and numpy 1.14.0. The pytest.approx behaves correctly.

@nicoddemus
Copy link
Member

Seems related to this feature which was introduced in 3.5.0:

pytest.approx now accepts comparing a numpy array with a scalar. (#3312)

So I believe we can close this @nosarthur?

@nicoddemus nicoddemus added status: needs information reporter needs to provide more information; can be closed after 2 or more weeks of inactivity and removed status: help wanted developers would like help from experts on this topic labels May 4, 2018
@nosarthur
Copy link
Author

Sure, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs information reporter needs to provide more information; can be closed after 2 or more weeks of inactivity
Projects
None yet
Development

No branches or pull requests

4 participants