Skip to content

Commit

Permalink
Refactored to_pint_quantity function (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
ka-sarthak authored Jan 12, 2024
1 parent 3a96488 commit 71b7e8c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/nomad_measurements/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ def merge_sections(

def to_pint_quantity(value: Any=None, unit: str=None) -> Any:
'''
Attempts to generate a pint quantity based on whether value or/and unit are available.
Attempts to generate a pint quantity.
In case the value is a string, it is returned as is.
Args:
value (Any): Value of the quantity.
Expand All @@ -122,6 +123,6 @@ def to_pint_quantity(value: Any=None, unit: str=None) -> Any:
Returns:
Any: Processed quantity with datatype depending on the value.
'''
if not unit:
if isinstance(value, str):
return value
return value * ureg(unit)

0 comments on commit 71b7e8c

Please sign in to comment.