Handle Excel errors in design matrices#13643
Draft
larsevj wants to merge 2 commits into
Draft
Conversation
- Centralize the reading of design matrices and catch errors for all uses.
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request improves robustness when reading Excel-based design matrices by centralizing polars.read_excel error handling and turning fastexcel cell errors (e.g., #NAME?) into configuration validation errors with clearer context.
Changes:
- Add a shared
_read_excel_with_contextwrapper to catchCalamineCellError/CalamineErrorand raise contextualValueErrors (wrapped intoConfigValidationErrorbyDesignMatrix). - Use the wrapper for reading design sheet headers/body and defaults sheet.
- Add regression unit tests ensuring Excel error cells in both design and default sheets raise
ConfigValidationError.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/ert/config/design_matrix.py |
Centralizes Excel read error handling and adds contextual error messages for invalid/corrupt Excel inputs. |
tests/ert/unit_tests/sensitivity_analysis/test_design_matrix.py |
Adds regression tests covering Excel error-cell scenarios for design/default sheets. |
Comment on lines
+257
to
264
| lambda: pl.read_excel( | ||
| self.xls_filename, | ||
| sheet_name=self.design_sheet, | ||
| has_header=False, | ||
| read_options={"n_rows": 1, "dtypes": "string"}, | ||
| ), | ||
| f"Design sheet '{self.design_sheet}' headers", | ||
| ) |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #13643 +/- ##
==========================================
- Coverage 89.57% 89.55% -0.03%
==========================================
Files 466 468 +2
Lines 32962 32983 +21
==========================================
+ Hits 29526 29537 +11
- Misses 3436 3446 +10
Flags with carried forward coverage won't be shown. Click here to find out more.
|
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.
Issue
Resolves #13628
Approach
Short description of the approach
(Screenshot of new behavior in GUI if applicable)
git rebase -i main --exec 'just rapid-tests')When applicable