diff --git a/HISTORY.rst b/HISTORY.rst index d0afbd4a..76d8876d 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -6,6 +6,12 @@ unyt began life as a submodule of yt named yt.units. It was separated from yt.units as its own package in 2018. +1.0.4 (2018-08-08) +------------------ + +* Expand installation instructions +* Mention paper and arxiv submission in the readme. + 1.0.3 (2018-06-06) ------------------ diff --git a/unyt/array.py b/unyt/array.py index 9d5c185c..6fa07163 100644 --- a/unyt/array.py +++ b/unyt/array.py @@ -1843,6 +1843,9 @@ def __new__(cls, input_scalar, input_units=None, registry=None, raise RuntimeError("unyt_quantity instances must be scalars") return ret + def __round__(self): + return type(self)(round(float(self)), self.units) + def _validate_numpy_wrapper_units(v, arrs): if not any(isinstance(a, unyt_array) for a in arrs): diff --git a/unyt/tests/test_unyt_array.py b/unyt/tests/test_unyt_array.py index 314c3e6d..73e0f1ce 100644 --- a/unyt/tests/test_unyt_array.py +++ b/unyt/tests/test_unyt_array.py @@ -1906,3 +1906,15 @@ def test_creation(): unyt_quantity('hello', 'cm') with pytest.raises(RuntimeError): unyt_quantity(np.array([1, 2, 3]), 'cm') + + +def test_round(): + from unyt import km + + assert_equal(round(3.3*km), 3.) + assert_equal(round(3.5*km), 4.) + assert_equal(round(3*km), 3) + assert_equal(round(3.7*km), 4) + + with pytest.raises(TypeError): + round([1, 2, 3]*km)