Skip to content

Navigation Menu

Sign in
Sign up

fix: two crashes when building cutouts and using years outside the input data - #2283

Open
18blasim wants to merge 3 commits into
PyPSA:master from
18blasim:fix/string-path-and-missing-year-fallback
Open

fix: two crashes when building cutouts and using years outside the input data #2283
18blasim wants to merge 3 commits into
PyPSA:master from
18blasim:fix/string-path-and-missing-year-fallback

Conversation

@18blasim

@18blasim 18blasim commented Sep 1, 2026
edited
Loading

Copy link
Copy Markdown

Fixes #2156, which I reported in April.

Both issues surfaced when running the workflow with a locally built cutout for a historical weather year (1990). They are independent, so feel free to ask me to split this PR.

  1. TypeError on the cutout path in rules/build_electricity.smk

dataset_version() in rules/common.smk builds the field with Path(...).as_posix(), so CUTOUT_DATASET["folder"] is a string. The build rule joins the filename with the / operator, which raises TypeError: unsupported operand type(s) for /: 'str' and 'str'. rules/retrieve.smk already uses + for the same variable, so this is an inconsistency between the two files. Only affects source: build, which is why it is easy to miss when using the pre-built cutouts.

  1. KeyError instead of the intended fallback in attach_conventional_generators

The code selects the snapshot year from a conventional input file and falls back to the last column, with the comment "take last column if year selection fails". However df[year] raises KeyError for a year that is not among the columns, and KeyError is not caught, so the fallback never triggers for the most common failure case.

This is not limited to unusual years: data/nuclear_p_max_pu.csv covers 2009 to 2024 but skips 2014, so even a year inside the nominal range aborts the run.

Adding KeyError to the existing except clause restores the documented behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Bug: TypeError when using source: build for cutout (str / str path division)

1 participant

AltStyle によって変換されたページ (->オリジナル) /