-
Notifications
You must be signed in to change notification settings - Fork 33
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
Fix numpy doctest #176
base: master
Are you sure you want to change the base?
Fix numpy doctest #176
Conversation
replace np.float_ with np.float64. The minimum numpy version 1.16 has both as aliases, the newer version numpy>=2.0 don't support np.float_ anymore.
[NEP51](https://numpy.org/neps/nep-0051-scalar-representation.html#backward-compatibility) changes the representation of scalars. While the long term strategy should be a comparison with the new form of representation, the discussion in [issue 24470](numpy/numpy#24470) seems to suggest to use an intermediate step while both, numpy-1 and numpy-2 are supported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I'm a bit worried about always changing the print option. We really only need this when running the tests. I have some local changes where this is under the control of an environment variable:
if os.environ.get('NAVIS_TEST_ENV', '').lower() == 'true':
import numpy as np
np.set_printoptions(legacy="1.25")
This would then require also changes to test_package.yml
and pytest.ini
to set that environment variable. Alternatively, you could invoke the set_printoptions
in conftest.py
- I haven't tried that though.
navis/morpho/mmetrics.py
Outdated
# Set up numpy number representation, see NEP51 | ||
# Once numpy<=2 is dropped from requirements, the doctest comparissons | ||
# should become `np.float64(1.074)` instead of `1.074` | ||
if int(np.version.version.split('.')[0])>=2: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would put this in config.py
- feels more appropriate when adjusting global settings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made the suggested changes.
In this scenario, the whole code basis gets switched to a different representation of np values. This means, in theory there could a piece of code that behaves differently in the NAVIS_TEST_ENV
than it does whenever you run the code without that variable set to true. I can't think of a case where this would matter. Since you were worried about "global" changes to the representation / print option, I also made an alternative PR #177, where the change of number representation should only change within the pydoctest.
This PR potentially improves the numpy>=2.0 compatibility
np.float_
as a dtype (and the minimum numpy version 1.16 seems to support both)np.float64(1.074)
, which fails the doctest when compared to1.074
). While numpy<2.0 is still an accepted dependency, I change the representation back to python scalars to pass the tests.This problem came up in #175, but is a separate issue, hence the separate PR.