The patch there is a backport of some upstream fixes and seems to be enough to fix the build (it has been uploaded to Ubuntu now)
yt/units/tests/test_ytarray.py | 15 +++++++++++++++ yt/units/yt_array.py | 23 ++++++++++++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-)
Index: yt-3.5.1/yt/units/tests/test_ytarray.py =================================================================== --- yt-3.5.1.orig/yt/units/tests/test_ytarray.py +++ yt-3.5.1/yt/units/tests/test_ytarray.py @@ -1379,3 +1379,18 @@ def test_ones_and_zeros_like(): assert_equal(zd.units, data.units) assert_equal(od, YTArray([1, 1, 1], 'cm')) assert_equal(od.units, data.units) + +def test_clip(): + km = YTQuantity(1, 'km') + + data = [1, 2, 3, 4, 5, 6] * km + answer = [2, 2, 3, 4, 4, 4] * km + + ret = np.clip(data, 2, 4) + assert_array_equal(ret, answer) + assert ret.units == answer.units + + np.clip(data, 2, 4, out=data) + + assert_array_equal(data, answer) + assert data.units == answer.units Index: yt-3.5.1/yt/units/yt_array.py =================================================================== --- yt-3.5.1.orig/yt/units/yt_array.py +++ yt-3.5.1/yt/units/yt_array.py @@ -50,6 +50,10 @@ from yt.utilities.exceptions import \ from yt.utilities.lru_cache import lru_cache from numbers import Number as numeric_type from yt.utilities.on_demand_imports import _astropy +try: + from numpy.core.umath import clip +except ImportError: + clip = None from sympy import Rational from yt.units.unit_lookup_table import \ default_unit_symbol_lut @@ -451,6 +455,7 @@ class YTArray(np.ndarray): divmod_: passthrough_unit, isnat: return_without_unit, heaviside: preserve_units, + clip: passthrough_unit, } __array_priority__ = 2.0 @@ -1396,9 +1401,28 @@ class YTArray(np.ndarray): out, out_arr, unit = handle_multiply_divide_units( unit, units, out, out_arr) else: - raise RuntimeError( - "Support for the %s ufunc with %i inputs has not been" - "added to YTArray." % (str(ufunc), len(inputs))) + if ufunc is clip: + inp = [] + for i in inputs: + if isinstance(i, YTArray): + inp.append(i.to(inputs[0].units).view(np.ndarray)) + elif iterable(i): + inp.append(np.asarray(i)) + else: + inp.append(i) + if out is not None: + _out = out.view(np.ndarray) + else: + _out = None + out_arr = ufunc(*inp, out=_out) + unit = inputs[0].units + ret_class = type(inputs[0]) + mul = 1 + else: + raise RuntimeError( + "Support for the %s ufunc with %i inputs has not been " + "added to unyt_array." % (str(ufunc), len(inputs)) + ) if unit is None: out_arr = np.array(out_arr, copy=False) elif ufunc in (modf, divmod_):