Skip to content

Commit

Permalink
black formatting and flake8 edits
Browse files Browse the repository at this point in the history
  • Loading branch information
mkhorton committed Aug 16, 2021
1 parent ed298ad commit b19e139
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.
23 changes: 14 additions & 9 deletions unyt/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
UnitConversionError,
UnitsNotReducible,
SymbolNotFoundError,
UnitOperationWarning
UnitOperationWarning,
)
from unyt.equivalencies import equivalence_registry
from unyt._on_demand_imports import _astropy, _pint
Expand Down Expand Up @@ -173,10 +173,7 @@ def _unit_operation_error_raise_or_warn(ufunc, u0, u1, func, *inputs):
raise UnitOperationError(ufunc, u0, u1)
else:
warnings.warn(UnitOperationWarning(ufunc, u0, u1))
unwrapped_inputs = [
i.value if isinstance(i, unyt_array)
else i for i in inputs
]
unwrapped_inputs = [i.value if isinstance(i, unyt_array) else i for i in inputs]
return func(*unwrapped_inputs)


Expand Down Expand Up @@ -1773,12 +1770,16 @@ def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
elif ufunc is power:
u1 = inp1
if inp0.shape != () and inp1.shape != ():
return _unit_operation_error_raise_or_warn(ufunc, u0, u1, func, *inputs)
return _unit_operation_error_raise_or_warn(
ufunc, u0, u1, func, *inputs
)
if isinstance(u1, unyt_array):
if u1.units.is_dimensionless:
pass
else:
return _unit_operation_error_raise_or_warn(ufunc, u0, u1.units, func, *inputs)
return _unit_operation_error_raise_or_warn(
ufunc, u0, u1.units, func, *inputs
)
if u1.shape == ():
u1 = float(u1)
else:
Expand Down Expand Up @@ -1828,9 +1829,13 @@ def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
ret = bool(ret)
return ret
else:
return _unit_operation_error_raise_or_warn(ufunc, u0, u1, func, *inputs)
return _unit_operation_error_raise_or_warn(
ufunc, u0, u1, func, *inputs
)
else:
return _unit_operation_error_raise_or_warn(ufunc, u0, u1, func, *inputs)
return _unit_operation_error_raise_or_warn(
ufunc, u0, u1, func, *inputs
)
conv, offset = u1.get_conversion_factor(u0, inp1.dtype)
new_dtype = np.dtype("f" + str(inp1.dtype.itemsize))
conv = new_dtype.type(conv)
Expand Down
21 changes: 5 additions & 16 deletions unyt/tests/test_unyt_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
UnitConversionError,
UnitOperationError,
UnitParseError,
UnitsNotReducible, UnitOperationWarning,
UnitsNotReducible,
UnitOperationWarning,
)
from unyt.testing import assert_allclose_units, _process_warning
from unyt.unit_symbols import cm, m, g, degree
Expand Down Expand Up @@ -2506,28 +2507,15 @@ def test_valid_quantity_from_string(s, expected):


@pytest.mark.parametrize(
"s",
[
"++1cm",
"--1cm",
"cm10",
"cm 10.",
".cm",
],
"s", ["++1cm", "--1cm", "cm10", "cm 10.", ".cm", ],
)
def test_invalid_expression_quantity_from_string(s):
with pytest.raises(ValueError, match=r"^(Received invalid quantity expression )"):
unyt_quantity.from_string(s)


@pytest.mark.parametrize(
"s",
[
"10 cmmmm",
"50. Km",
".6 MSUN",
"infcm", # space sep is required here
],
"s", ["10 cmmmm", "50. Km", ".6 MSUN", "infcm", ], # space sep is required here
)
def test_invalid_unit_quantity_from_string(s):
# using a lazy solution here
Expand All @@ -2540,6 +2528,7 @@ def test_invalid_unit_quantity_from_string(s):
):
unyt_quantity.from_string(s)


def test_non_strict_registry():

reg = UnitRegistry(strict=False)
Expand Down

0 comments on commit b19e139

Please sign in to comment.