Skip to content

Commit a6cf636

Browse files
committed
Backport PR #1792: Fix/support compatible units in time series specs (#1792)
* feat: add doctest to VariableQuantityField._get_unit Signed-off-by: F.N. Claessen <felix@seita.nl> * fix: allow convertible units in time series specs Signed-off-by: F.N. Claessen <felix@seita.nl> * docs: touch up some previous changelog entries under v0.29.1 Signed-off-by: F.N. Claessen <felix@seita.nl> * docs: changelog entry Signed-off-by: F.N. Claessen <felix@seita.nl> * docs: update month for v0.29.1 Signed-off-by: F.N. Claessen <felix@seita.nl> * fix: do not allow mixing kW and kWh units within a single time series specification Signed-off-by: F.N. Claessen <felix@seita.nl> --------- Signed-off-by: F.N. Claessen <felix@seita.nl> (cherry picked from commit 8ce07b4) Signed-off-by: F.N. Claessen <felix@seita.nl>
1 parent 33ee31d commit a6cf636

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

documentation/changelog.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ FlexMeasures Changelog
44
**********************
55

66

7-
v0.29.1 | October XX, 2025
7+
v0.29.1 | November 5, 2025
88
============================
99

1010
Bugfixes
1111
-----------
12+
* Support different but still compatible units in time series segments of variable quantities [see `PR #1792 <https://www.github.com/FlexMeasures/flexmeasures/pull/1792>`_]
1213
* Fix account and `/assets/owned_by` pages rendering, giving them asset icons [see `PR #1772 <https://github.com/FlexMeasures/flexmeasures/pull/1772>`_]
1314
* Allow consultants to view client users [see `PR #1755 <https://www.github.com/FlexMeasures/flexmeasures/pull/1755>`_]
1415
* Fix bug where removed flex-model fields don't show up under the dropdown for new fields, except after a page refresh [see `PR #1775 <https://www.github.com/FlexMeasures/flexmeasures/pull/1775>`_]

flexmeasures/data/schemas/sensors.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,13 +431,23 @@ def _get_original_unit(
431431
return unit
432432

433433
def _get_unit(self, variable_quantity: ur.Quantity | list[dict] | Sensor) -> str:
434-
"""Obtain the unit from the (deserialized) variable quantity."""
434+
"""Obtain the unit from the (deserialized) variable quantity.
435+
436+
>>> VariableQuantityField("MW")._get_unit(ur.Quantity("3 kWh"))
437+
'kWh'
438+
>>> VariableQuantityField("/MW")._get_unit([{'value': ur.Quantity("3 kEUR/MWh")}, {'value': ur.Quantity("0 EUR/kWh")}])
439+
'kEUR/MWh'
440+
"""
435441
if isinstance(variable_quantity, ur.Quantity):
436442
unit = str(variable_quantity.units)
437443
elif isinstance(variable_quantity, list):
438444
unit = str(variable_quantity[0]["value"].units)
439445
if not all(
440-
str(variable_quantity[j]["value"].units) == unit
446+
units_are_convertible(
447+
from_unit=str(variable_quantity[j]["value"].units),
448+
to_unit=unit,
449+
duration_known=False, # prevent mistakes by not allowing to mix kW and kWh units within a single time series specification
450+
)
441451
for j in range(len(variable_quantity))
442452
):
443453
raise ValidationError(

0 commit comments

Comments
 (0)