Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion gemd/units/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ def convert_units(value: float, starting_unit: str, final_unit: str) -> float:
The converted number

"""
return _ureg.Quantity(value, starting_unit).to(final_unit).magnitude
if starting_unit == final_unit:
return value # skip computation
else:
return _ureg.Quantity(value, starting_unit).to(final_unit).magnitude


def change_definitions_file(filename: str = None):
Expand Down
4 changes: 2 additions & 2 deletions gemd/units/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ def test_file_change():
"""Test that swapping units files works."""
assert convert_units(1, 'm', 'cm') == 100
with pytest.raises(UndefinedUnitError):
assert convert_units(1, 'usd', 'usd') == 1
assert convert_units(1, 'usd', 'USD') == 1
with _change_units(filename=pkg_resources.resource_filename("gemd.units",
"tests/test_units.txt")):
with pytest.raises(UndefinedUnitError):
assert convert_units(1, 'm', 'cm') == 100
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

assert convert_units(1, 'usd', 'usd') == 1
assert convert_units(1, 'usd', 'USD') == 1
assert convert_units(1, 'm', 'cm') == 100 # And verify we're back to normal
2 changes: 1 addition & 1 deletion gemd/units/tests/test_units.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

#### BASE UNITS ####

usd = [currency]
usd = [currency] = USD
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


setup(name='gemd',
version='1.10.2',
version='1.10.3',
url='http://github.com/CitrineInformatics/gemd-python',
description="Python binding for Citrine's GEMD data model",
author='Citrine Informatics',
Expand Down