-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use NP_COPY_IF_NEEDED for compatibility with new copy semantics
With NumPy 2.0.0, `copy=False` now raises a ValueError if the copy cannot be made. The previous behavior to only copy if needed is provided with `copy=None`. During the transition period, use this symbol instead. Remove once NumPy 2.0.0 is the minimal required version [1, 2] This approach was inspired by astropy [3]. [1] https://numpy.org/devdocs/release/2.0.0-notes.html#new-copy-keyword-meaning-for-array-and-asarray-constructors [2] https://www.github.com/numpy/numpy/pull/25168 [3] https://github.com/astropy/astropy/blob/2390bf8f8f2a1c5b6beffbd87db9af5aa6538df1/astropy/utils/compat/numpycompat.py#L29
- Loading branch information
Showing
6 changed files
with
33 additions
and
3 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"""Compatibility helpers for dependencies.""" | ||
|
||
from packaging.version import parse | ||
|
||
import numpy as np | ||
|
||
|
||
__all__ = [ | ||
"NUMPY_LT_2_0_0", | ||
"NP_COPY_IF_NEEDED", | ||
] | ||
|
||
|
||
NUMPY_LT_2_0_0 = parse(np.__version__) < parse('2.0.0.dev0') | ||
|
||
# With NumPy 2.0.0, `copy=False` now raises a ValueError if the copy cannot be | ||
# made. The previous behavior to only copy if needed is provided with `copy=None`. | ||
# During the transition period, use this symbol instead. | ||
# Remove once NumPy 2.0.0 is the minimal required version. | ||
# https://numpy.org/devdocs/release/2.0.0-notes.html#new-copy-keyword-meaning-for-array-and-asarray-constructors | ||
# https://github.com/numpy/numpy/pull/25168 | ||
NP_COPY_IF_NEEDED = False if NUMPY_LT_2_0_0 else None |
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
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
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
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