Skip to content

Commit

Permalink
Merge pull request #131 from l-johnston/fix_unitoperationerror_exception
Browse files Browse the repository at this point in the history
fix UnitOperationError exception when the exponent is unyt_array or u…
  • Loading branch information
ngoldbaum authored Jan 27, 2020
2 parents 595b9cd + e78ad73 commit 890fe89
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion unyt/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1666,7 +1666,7 @@ def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
if u1.units.is_dimensionless:
pass
else:
raise UnitOperationError(ufunc, u0, u1)
raise UnitOperationError(ufunc, u0, u1.units)
if u1.shape == ():
u1 = float(u1)
else:
Expand Down
8 changes: 7 additions & 1 deletion unyt/tests/test_unyt_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
from unyt.unit_registry import UnitRegistry
from unyt._on_demand_imports import _astropy, _h5py, _pint, NotAModule
from unyt._physical_ratios import metallicity_sun, speed_of_light_cm_per_s
from unyt import dimensions
from unyt import dimensions, Unit


def operate_and_compare(a, b, op, answer):
Expand Down Expand Up @@ -498,6 +498,12 @@ def test_power():
with pytest.raises(UnitOperationError):
np.power(cm_arr, unyt_quantity(3, "g"))

try:
np.power(cm_arr, unyt_quantity(3, "g"))
except UnitOperationError as err:
assert isinstance(err.unit1, Unit)
assert isinstance(err.unit2, Unit)


def test_comparisons():
"""
Expand Down

0 comments on commit 890fe89

Please sign in to comment.