diff --git a/src/finam/adapters/base.py b/src/finam/adapters/base.py index 1a93519314df10c6e6c7aa8c6098e67a04e0551b..b8055b7ac6fff8851761ae1dcba3fd860c02cfec 100644 --- a/src/finam/adapters/base.py +++ b/src/finam/adapters/base.py @@ -4,7 +4,7 @@ Basic data transformation adapters. import numpy as np from ..data.grid_spec import NoGrid -from ..data.tools import get_magnitude, get_units +from ..data.tools import get_magnitude, get_units, quantify from ..errors import FinamMetaDataError from ..sdk import Adapter from ..tools.log_helper import ErrorLogger @@ -139,9 +139,12 @@ class ValueToGrid(Adapter): data-set for the requested time. """ value = self.pull_data(time, target) - return np.full( - self._info.grid.data_shape, get_magnitude(value), dtype=value.dtype - ) * get_units(value) + return quantify( + np.full( + self._info.grid.data_shape, get_magnitude(value), dtype=value.dtype + ), + get_units(value), + ) def _get_info(self, info): up_info = info.copy_with(grid=NoGrid()) @@ -196,7 +199,7 @@ class GridToValue(Adapter): """ grid = self.pull_data(time, target) - func_result = self.func(get_magnitude(grid)) * get_units(grid) + func_result = quantify(self.func(get_magnitude(grid)), get_units(grid)) return func_result diff --git a/src/finam/modules/readers.py b/src/finam/modules/readers.py index b85fed6f9bdb2ce175c9274cc4e59ffa9d90591f..760edcb6f01c9bc231a420f42d3646dd7a52f77d 100644 --- a/src/finam/modules/readers.py +++ b/src/finam/modules/readers.py @@ -7,7 +7,7 @@ from datetime import datetime from finam.interfaces import ComponentStatus from ..data.grid_spec import NoGrid -from ..data.tools import UNITS, Info +from ..data.tools import Info, quantify from ..sdk import TimeComponent @@ -151,7 +151,7 @@ class CsvReader(TimeComponent): time = datetime.strptime(row[self._time_column], self._date_format) out_data = { - name: row[name] * UNITS.Unit(units) + name: quantify(row[name], units) for name, units in self._output_units.items() }