Skip to content
Snippets Groups Projects
Commit f0350d25 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Fixed bug in unit conversion optimization.

parent 1d1192df
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,7 @@ import re
import logging
from pint import UnitRegistry
import cachetools
import numpy as np
logger = logging.getLogger(__name__)
# disable warnings from pint
logging.getLogger("pint").setLevel(logging.ERROR)
......@@ -58,7 +59,13 @@ def convert_unit(value, unit, target_unit=None):
"""
factor = get_multiplicative_factor(unit, target_unit)
if factor is not None:
return value * factor
try:
if isinstance(value, (list, tuple)):
return (np.array(value) * factor).tolist()
else:
return value * factor
except Exception as e:
logger.error('could not perform optimized unit conversion', exc_info=e)
# Check that the unit is valid
unit_def = ureg_cached(unit)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment