Skip to content

Commit dfd60b4

Browse files
authored
Merge pull request #492 from neutrinoceros/numpy2/copy_semantics
2 parents 37abbd9 + d897f42 commit dfd60b4

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

unyt/array.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import sys
1111
import warnings
1212
from functools import lru_cache
13+
from importlib.metadata import version
1314
from numbers import Number as numeric_type
1415

1516
import numpy as np
@@ -102,6 +103,7 @@
102103
true_divide,
103104
trunc,
104105
)
106+
from packaging.version import Version
105107
from sympy import Rational
106108

107109
from unyt._on_demand_imports import _astropy, _dask, _pint
@@ -146,6 +148,8 @@
146148
("unyt_array.from_astropy", "unyt_array.to_astropy"): ["astropy"],
147149
}
148150

151+
_COPY_IF_NEEDED = None if Version(version("numpy")) >= Version("2.0.0dev0") else False
152+
149153
# This is partially adapted from the following SO thread
150154
# https://stackoverflow.com/questions/41668588/regex-to-match-scientific-notation
151155
_NUMB_PATTERN = (
@@ -1985,7 +1989,7 @@ def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
19851989
"added to unyt_array." % (str(ufunc), len(inputs))
19861990
)
19871991
if unit is None:
1988-
out_arr = np.array(out_arr, copy=False)
1992+
out_arr = np.array(out_arr, copy=_COPY_IF_NEEDED)
19891993
elif ufunc in (modf, divmod_):
19901994
out_arr = tuple(ret_class(o, unit) for o in out_arr)
19911995
elif out_arr.shape == ():

0 commit comments

Comments
 (0)