Skip to content

Commit

Permalink
Merge pull request #57 from metno/eea_parquet_multi_units
Browse files Browse the repository at this point in the history
Check if units are equivalent
  • Loading branch information
magnusuMET authored Jan 17, 2025
2 parents 76acc8e + 848d21d commit b7e0200
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ install_requires =
numpy
xarray
cfunits
cf-units
polars[pyarrow]
tomli>=2.0.1; python_version < "3.11"

Expand Down
9 changes: 8 additions & 1 deletion src/pyaro_readers/eeareader/EEATimeseriesReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from tqdm import tqdm
import numpy as np
import cf_units
import polars
from pyaro.timeseries.AutoFilterReaderEngine import (
AutoFilterReader,
Expand Down Expand Up @@ -39,7 +40,13 @@ def units(self) -> str:
if len(units) == 0:
raise EEAReaderException("No units present in this dataset")
elif len(units) != 1:
raise EEAReaderException("Multiple different units present in this dataset")
base_unit = cf_units.Unit(units[0])
for unit in units[1:]:
if base_unit.convert(1, unit) != 1.0:
raise EEAReaderException(
f"Multiple different units present in this dataset ({units[0]} and {unit})"
)

return units[0]

def keys(self):
Expand Down

0 comments on commit b7e0200

Please sign in to comment.