-
Notifications
You must be signed in to change notification settings - Fork 515
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 2.0 deprecations via running ruff #2580
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
komoto48g
reviewed
Jul 20, 2024
…fix --exclude docs/sphinx/rest_substitutions/snippets/python/converted` See https://numpy.org/devdocs/numpy_2_0_migration_guide.html#numpy-2-0-migration-guide
… multidimensional arrays.
radoering
force-pushed
the
numpy-2-compat
branch
from
July 20, 2024 05:46
25901b6
to
4e09cda
Compare
Closed
Please merge. |
The unit tests have been missed by this PR: [ 1232s] =================================== FAILURES ===================================
[ 1232s] __________________________ testFromPoints.testCreate ___________________________
[ 1232s] [gw0] linux -- Python 3.10.14 /usr/bin/python3.10
[ 1232s] self = <unittests.test_lib_floatcanvas_bbox.testFromPoints testMethod=testCreate>
[ 1232s]
[ 1232s] def testCreate(self):
[ 1232s] Pts = N.array( ((5,2),
[ 1232s] (3,4),
[ 1232s] (1,6),
[ 1232s] > ), N.float_ )
[ 1232s]
[ 1232s] unittests/test_lib_floatcanvas_bbox.py:344:
[ 1232s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
[ 1232s]
[ 1232s] attr = 'float_'
[ 1232s]
[ 1232s] def __getattr__(attr):
[ 1232s] # Warn for expired attributes
[ 1232s] import warnings
[ 1232s]
[ 1232s] if attr == "linalg":
[ 1232s] import numpy.linalg as linalg
[ 1232s] return linalg
[ 1232s] elif attr == "fft":
[ 1232s] import numpy.fft as fft
[ 1232s] return fft
[ 1232s] elif attr == "dtypes":
[ 1232s] import numpy.dtypes as dtypes
[ 1232s] return dtypes
[ 1232s] elif attr == "random":
[ 1232s] import numpy.random as random
[ 1232s] return random
[ 1232s] elif attr == "polynomial":
[ 1232s] import numpy.polynomial as polynomial
[ 1232s] return polynomial
[ 1232s] elif attr == "ma":
[ 1232s] import numpy.ma as ma
[ 1232s] return ma
[ 1232s] elif attr == "ctypeslib":
[ 1232s] import numpy.ctypeslib as ctypeslib
[ 1232s] return ctypeslib
[ 1232s] elif attr == "exceptions":
[ 1232s] import numpy.exceptions as exceptions
[ 1232s] return exceptions
[ 1232s] elif attr == "testing":
[ 1232s] import numpy.testing as testing
[ 1232s] return testing
[ 1232s] elif attr == "matlib":
[ 1232s] import numpy.matlib as matlib
[ 1232s] return matlib
[ 1232s] elif attr == "f2py":
[ 1232s] import numpy.f2py as f2py
[ 1232s] return f2py
[ 1232s] elif attr == "typing":
[ 1232s] import numpy.typing as typing
[ 1232s] return typing
[ 1232s] elif attr == "rec":
[ 1232s] import numpy.rec as rec
[ 1232s] return rec
[ 1232s] elif attr == "char":
[ 1232s] import numpy.char as char
[ 1232s] return char
[ 1232s] elif attr == "array_api":
[ 1232s] raise AttributeError("`numpy.array_api` is not available from "
[ 1232s] "numpy 2.0 onwards")
[ 1232s] elif attr == "core":
[ 1232s] import numpy.core as core
[ 1232s] return core
[ 1232s] elif attr == "strings":
[ 1232s] import numpy.strings as strings
[ 1232s] return strings
[ 1232s] elif attr == "distutils":
[ 1232s] if 'distutils' in __numpy_submodules__:
[ 1232s] import numpy.distutils as distutils
[ 1232s] return distutils
[ 1232s] else:
[ 1232s] raise AttributeError("`numpy.distutils` is not available from "
[ 1232s] "Python 3.12 onwards")
[ 1232s]
[ 1232s] if attr in __future_scalars__:
[ 1232s] # And future warnings for those that will change, but also give
[ 1232s] # the AttributeError
[ 1232s] warnings.warn(
[ 1232s] f"In the future `np.{attr}` will be defined as the "
[ 1232s] "corresponding NumPy scalar.", FutureWarning, stacklevel=2)
[ 1232s]
[ 1232s] if attr in __former_attrs__:
[ 1232s] raise AttributeError(__former_attrs__[attr])
[ 1232s]
[ 1232s] if attr in __expired_attributes__:
[ 1232s] > raise AttributeError(
[ 1232s] f"`np.{attr}` was removed in the NumPy 2.0 release. "
[ 1232s] f"{__expired_attributes__[attr]}"
[ 1232s] )
[ 1232s] E AttributeError: `np.float_` was removed in the NumPy 2.0 release. Use `np.float64` instead.. Did you mean: 'float16'?
[ 1232s]
[ 1232s] /usr/lib64/python3.10/site-packages/numpy/__init__.py:397: AttributeError
And so on. Please fix before the 4.2.2 release |
Interesting. I assume ruff missed that because numpy is not imported directly in the unit test but via a star import from |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I just run the following command:
to fix numpy deprecations that were removed and thereby result in an exception with numpy 2.0.
See https://numpy.org/devdocs/numpy_2_0_migration_guide.html#numpy-2-0-migration-guide
Fixes #2574
Fixes #2498
Closes #2578