Conversation
fneum
approved these changes
Dec 10, 2025
lkstrp
approved these changes
Dec 11, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follows discussion in #1454
Changes proposed in this Pull Request
When using
optimize_with_rolling_horizonwithlinearized_unit_commitmentand ramp limits defined for committable generators, the optimization fails with "KeyError: "not all values found in index 'snapshot'". Here is a minimalistic example to reproduce h/t @thomgeo(FYI @thomgeo though it is not related to ramp values >1 per se)
The error occurs in the ramp limit constraints for committable components when trying to adjust the RHS for the first snapshot of each rolling horizon window. The problematic code is here:
PyPSA/pypsa/optimization/constraints.py
Lines 783 to 788 in 16d6a73
If we step in with debugger in this line for an example above: the .item(0) method returns the snapshot coordinate's int64 representation instead of a datetime object.
Later this integer is used to index into a DatetimeIndex, and pandas complains.
For the fix I use xarray position-based .isel() indexing instead for two places in the code (ramp up/down). I'll add some tests too later tonight.
Checklist
docs.docs/release-notes.mdof the upcoming release is included.