Skip to content

Commit

Permalink
Adapt chempy.units to latest version of quantities
Browse files Browse the repository at this point in the history
  • Loading branch information
bjodah committed Jul 16, 2023
1 parent c449eb0 commit 5cd64c1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion chempy/tests/test_units.py
Expand Up @@ -221,7 +221,7 @@ def test_to_unitless__sympy():
import sympy as sp

assert sp.cos(to_unitless(sp.pi)) == -1
with pytest.raises(AttributeError):
with pytest.raises(Exception):
to_unitless(sp.pi, u.second)


Expand Down
5 changes: 4 additions & 1 deletion chempy/units.py
Expand Up @@ -386,7 +386,10 @@ def to_unitless(value, new_unit=None):
else:
try:
try:
result = (value * pq.dimensionless / new_unit).rescale(pq.dimensionless)
mag = magnitude(value)
unt = unit_of(value)
conv = rescale(unt/new_unit, pq.dimensionless)
result = np.array(mag)*conv
except AttributeError:
if new_unit == pq.dimensionless:
return value
Expand Down

0 comments on commit 5cd64c1

Please sign in to comment.