Skip to content

Commit

Permalink
Merge pull request #492 from neutrinoceros/numpy2/copy_semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
jzuhone authored Mar 12, 2024
2 parents 37abbd9 + d897f42 commit dfd60b4
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion unyt/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import sys
import warnings
from functools import lru_cache
from importlib.metadata import version
from numbers import Number as numeric_type

import numpy as np
Expand Down Expand Up @@ -102,6 +103,7 @@
true_divide,
trunc,
)
from packaging.version import Version
from sympy import Rational

from unyt._on_demand_imports import _astropy, _dask, _pint
Expand Down Expand Up @@ -146,6 +148,8 @@
("unyt_array.from_astropy", "unyt_array.to_astropy"): ["astropy"],
}

_COPY_IF_NEEDED = None if Version(version("numpy")) >= Version("2.0.0dev0") else False

# This is partially adapted from the following SO thread
# https://stackoverflow.com/questions/41668588/regex-to-match-scientific-notation
_NUMB_PATTERN = (
Expand Down Expand Up @@ -1985,7 +1989,7 @@ def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
"added to unyt_array." % (str(ufunc), len(inputs))
)
if unit is None:
out_arr = np.array(out_arr, copy=False)
out_arr = np.array(out_arr, copy=_COPY_IF_NEEDED)
elif ufunc in (modf, divmod_):
out_arr = tuple(ret_class(o, unit) for o in out_arr)
elif out_arr.shape == ():
Expand Down

0 comments on commit dfd60b4

Please sign in to comment.