Add schemas for the custom-constraint tables#120
Merged
Conversation
The templater has emitted custom_constraints, custom_constraints_lhs and custom_constraints_rhs since the PLEXOS templater landed, but the tables had no schemas, so user-supplied versions of them had no documented contract. The schemas pin the vocabulary the translator now relies on: direction senses (<=, >=, =), term types (including load, which the 7.5 PLEXOS extract emits for Node Load Coefficient terms), the timeslice cross-reference, and date_from semantics (the value active at the start of an investment period applies for that whole period). Also fixes network_expansion_options cross-referencing the non-existent constraints_rhs table. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 🚀 New features to boost your workflow:
|
The custom_validation rules on these schemas only existed to express "uniqueness with NaN counted as a single value". Pinning down unique: to treat NaN as equal (#122) lets a plain unique: carry that guarantee, so the three rules become unique: declarations. For network_transmission_path_limits and custom_constraints_rhs this also revises what a NaN timeslice means: rather than a static limit applying to all conditions (mutually exclusive with per-timeslice rows), it is now a fallback applying only where no per-timeslice row covers, so both forms may co-exist. Documented under the timeslice column. Also adds generator_capacity to the lhs term_type allowed values. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
EllieKallmier
approved these changes
Jun 19, 2026
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.
Adds validation schemas for the custom-constraint tables, updates unique row validation logic, and timeslice NaN logic.
Broader changes than just adding the custom constraint schemas
1. Uniqueness is now plain
unique:, replacing bespokecustom_validation.The three tables whose uniqueness key includes a nullable column —
custom_constraints_lhs→[constraint_id, term_type, variable_name, date_from]custom_constraints_rhs→[constraint_id, timeslice, date_from]network_transmission_path_limits→[path_id, direction, timeslice]— previously carried hand-written
custom_validationrules whose only job wasto spell out the NaN handling. They are now plain
unique:declarations. Thisrelies on a decision to have
unique:treat NaN as equal to NaN (pandasduplicated()semantics), so at most one otherwise-identical NaN row ispermitted per group — standard SQL
UNIQUEwould treat NULLs as distinct andlet duplicates through. The contract is recorded in #122, which
also tracks where to document it centrally.
2. A NaN timeslice now means "fallback", not "all conditions".
Previously a no-timeslice row in
custom_constraints_rhsandnetwork_transmission_path_limitswas read as a static limit applying to alldemand conditions, effectively mutually exclusive with per-timeslice rows. It
is now a fallback: it applies only at snapshots not covered by any
per-timeslice row for the same group, with per-timeslice rows taking precedence
where they overlap — so the two forms may co-exist. Documented under the
timeslicecolumn in both tables.This second change is a behavioural contract for whatever applies these limits
downstream: the fallback/precedence logic still needs to be implemented there.