Add helper for validating finite, non-negative inputs - #1468
Open
alexdewar wants to merge 2 commits into
Open
Conversation
alexdewar
force-pushed
the
deserialise-finite-non-negative-helper
branch
from
July 31, 2026 16:58
2229824 to
0736385
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1468 +/- ##
=======================================
Coverage 89.80% 89.80%
=======================================
Files 60 60
Lines 8443 8436 -7
Branches 8443 8436 -7
=======================================
- Hits 7582 7576 -6
Misses 544 544
+ Partials 317 316 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors repeated “finite and non-negative” numeric validation into a shared Serde deserialisation helper, reducing duplicated validation code and associated tests across input and model-parameter parsing.
Changes:
- Added
deserialise_finite_non_negativeto centralise validation for finite, non-negative numeric inputs during deserialisation. - Updated
ModelParametersfields to use the new helper and removed now-redundant per-field validation functions/tests. - Updated commodity demand CSV parsing to validate
demandvia the new deserialiser and removed redundant runtime checks/tests.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/model/parameters.rs | Uses the new deserialiser for several parameters and removes duplicated validation helpers/tests. |
| src/input/commodity/demand.rs | Moves demand non-negativity/finite validation into Serde deserialisation and drops redundant checks/tests. |
| src/input.rs | Introduces deserialise_finite_non_negative plus a focused unit test. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Ok(()) | ||
| } | ||
|
|
||
| /// Check that the `remaining_demand_absolute_tolerance` parameter is valid. |
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.
Description
There are loads of places in
parameters.rswhere we check that a number is finite and non-negative (I remembered this when I spotted another in #1463). Replace with a helper,deserialise_finite_non_negative, which works much like the existingdeserialise_nonzero. This means we can remove duplicated code and some redundant tests, too.Type of change
Key checklist
$ cargo test$ cargo docpresent in the previous release
Further checks