Skip to content

Commit

Permalink
chore: make sure no mismatch between timestemps and time series values
Browse files Browse the repository at this point in the history
  • Loading branch information
frodehk committed Oct 24, 2023
1 parent b580e3d commit d70412a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/libecalc/common/utils/rates.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,23 @@ def convert_none_to_nan(cls, v: float, field: ModelField) -> TimeSeriesValue:
return math.nan
return v

@validator("values", pre=True)
def timesteps_values_one_to_one(cls, v: list, values, field: ModelField):
nr_timesteps = len(values["timesteps"])
nr_values = len(v)

if not cls.__name__ == TimeSeriesVolumes.__name__:
if nr_timesteps != nr_values:
if all(math.isnan(i) for i in v):
# TODO: This should probably be solved another place. Temporary solution to make things run
return [math.nan] * len(values["timesteps"])
else:
raise ProgrammingError(
"Time series: number of timesteps do not match number "
"of values. Most likely a bug, report to eCalc Dev Team."
)
return v

def __len__(self) -> int:
return len(self.values)

Expand Down

0 comments on commit d70412a

Please sign in to comment.