Skip to content

Commit a36d044

Browse files
authored
Allow models with only flexible inputs (#816)
1 parent 5d0ce3a commit a36d044

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

src/muse/readers/csv.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -569,11 +569,20 @@ def process_io_technodata(data: pd.DataFrame) -> xr.Dataset:
569569
# Create xarray dataset
570570
result = create_xarray_dataset(data)
571571

572-
# Fill in flexible data
573-
if "flexible" in result.data_vars:
574-
result["flexible"] = result.flexible.fillna(0)
575-
else:
572+
# Ensure both `fixed` and `flexible` inputs/outputs are defined. If only one is
573+
# defined in the input data, create the other as a zeros array with the same shape.
574+
has_fixed = "fixed" in result.data_vars
575+
has_flexible = "flexible" in result.data_vars
576+
if has_fixed and not has_flexible:
576577
result["flexible"] = xr.zeros_like(result.fixed).rename("flexible")
578+
elif has_flexible and not has_fixed:
579+
result["fixed"] = xr.zeros_like(result.flexible).rename("fixed")
580+
elif not has_fixed and not has_flexible:
581+
raise ValueError("Neither 'fixed' nor 'flexible' levels were found.")
582+
583+
# Fill any NaNs with zero
584+
result["fixed"] = result.fixed.fillna(0)
585+
result["flexible"] = result.flexible.fillna(0)
577586

578587
# Check commodities
579588
result = check_commodities(result, fill_missing=True, fill_value=0)

0 commit comments

Comments
 (0)