Skip to content

Raise clear error for PEtab YAML with empty 'problems' section - #521

Merged
dweindl merged 1 commit into
PEtab-dev:mainfrom
dweindl:fix-218-missing-problems
Sep 22, 2026
Merged

dweindl merged 1 commit into
PEtab-dev:mainfrom
dweindl:fix-218-missing-problems

Conversation

@dweindl

@dweindl dweindl commented Sep 22, 2026

Copy link
Copy Markdown
Member

Fixes the remaining part of #218.

The originally reported KeyError: 'parameter_file' no longer occurs, since Problem.from_yaml now builds a pydantic ProblemConfig, which already gives parameter_file/sbml_files sane defaults. However, the same class of problem still exists for problems: ProblemConfig.problems defaults to [] when the key is missing from the YAML (or is given explicitly as problems: []), and Problem.from_yaml then indexes into it unconditionally (config.problems[0]), raising a raw IndexError (is_composite_problem() similarly raised a raw KeyError beforehand).

So this isn't really about a "missing" key — it's about an empty problems section, however it comes to be empty. This adds a clear ValueError for that case, and a parametrized regression test covering both the missing-key and explicit-empty-list cases.

🤖 Generated with Claude Code

@codecov-commenter

codecov-commenter commented Sep 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.15%. Comparing base (02fd94e) to head (764b2be).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #521   +/-   ##
=======================================
  Coverage   76.14%   76.15%           
=======================================
  Files          67       67           
  Lines        7526     7528    +2     
  Branches     1341     1342    +1     
=======================================
+ Hits         5731     5733    +2     
  Misses       1294     1294           
  Partials      501      501           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

`Problem.from_yaml` raised a raw `KeyError`/`IndexError` when the
`problems` list was empty or absent (which pydantic silently defaults
to an empty list), instead of a helpful message.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@dweindl
dweindl force-pushed the fix-218-missing-problems branch from 9537e00 to 764b2be Compare September 22, 2026 15:01
@dweindl dweindl changed the title Raise clear error for PEtab YAML missing 'problems' section Raise clear error for PEtab YAML with empty 'problems' section Sep 22, 2026
@dweindl
dweindl marked this pull request as ready for review September 22, 2026 16:04
@dweindl
dweindl requested a review from a team as a code owner September 22, 2026 16:04
@dweindl
dweindl merged commit 2610499 into PEtab-dev:main Sep 22, 2026
7 checks passed
@dweindl
dweindl deleted the fix-218-missing-problems branch September 22, 2026 20:19
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.

3 participants