Skip to content

Handle Excel errors in design matrices#13643

Draft
larsevj wants to merge 2 commits into
equinor:mainfrom
larsevj:catch_more_calamine_errors_design_matrix
Draft

Handle Excel errors in design matrices#13643
larsevj wants to merge 2 commits into
equinor:mainfrom
larsevj:catch_more_calamine_errors_design_matrix

Conversation

@larsevj
Copy link
Copy Markdown
Collaborator

@larsevj larsevj commented May 28, 2026

  • Centralize the reading of design matrices and catch errors for all uses.

Issue
Resolves #13628

Approach
Short description of the approach

(Screenshot of new behavior in GUI if applicable)

  • PR title captures the intent of the changes, and is fitting for release notes.
  • Added appropriate release note label
  • Commit history is consistent and clean, in line with the contribution guidelines.
  • Make sure unit tests pass locally after every commit (git rebase -i main --exec 'just rapid-tests')

When applicable

  • When there are user facing changes: Updated documentation
  • New behavior or changes to existing untested code: Ensured that unit tests are added (See Ground Rules).
  • Large PR: Prepare changes in small commits for more convenient review
  • Bug fix: Add regression test for the bug
  • Bug fix: Add backport label to latest release (format: 'backport release-branch-name')

- Centralize the reading of design matrices and catch
 errors for all uses.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_context wrapper to catch CalamineCellError / CalamineError and raise contextual ValueErrors (wrapped into ConfigValidationError by DesignMatrix).
  • 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-commenter
Copy link
Copy Markdown

codecov-commenter commented May 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.55%. Comparing base (cc26b7e) to head (181b4b4).
⚠️ Report is 4 commits behind head on main.
✅ All tests successful. No failed tests found.

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     
Flag Coverage Δ
cli-tests 35.67% <60.00%> (-0.02%) ⬇️
fuzz 43.94% <30.00%> (+0.02%) ⬆️
gui-tests 59.78% <60.00%> (+0.01%) ⬆️
performance-and-unit-tests 78.02% <100.00%> (-0.08%) ⬇️
test 45.41% <30.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/ert/config/design_matrix.py 97.38% <100.00%> (+0.08%) ⬆️

... and 1 file with indirect coverage changes

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ert does not handle fastexcel errors

3 participants