Skip to content

Omit empty optional entries in ProblemConfig.to_yaml - #547

Merged
dweindl merged 2 commits into
PEtab-dev:mainfrom
dweindl:sparse_yaml
Oct 15, 2026
Merged

dweindl merged 2 commits into
PEtab-dev:mainfrom
dweindl:sparse_yaml

Conversation

@dweindl

@dweindl dweindl commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

ProblemConfig.to_yaml wrote condition_files: [], experiment_files: [], mapping_files: [] and extensions: {} whenever these weren't set. The PEtab v2 schema doesn't require them. They add noise, and they make files written by libpetab differ from files written by hand to the spec. This affects everything that goes through to_yaml, including Problem.to_files and petab1to2.

These four entries are now left out when they're empty. Required entries (parameter_files, model_files, measurement_files, observable_files) are still written even when empty, so that a schema violation stays visible. Reading problems without these entries already worked, so only the writer changes.

The required and optional keys are now available as petab.v2.C.PROBLEM_CONFIG_REQUIRED_KEYS and petab.v2.C.PROBLEM_CONFIG_OPTIONAL_KEYS. A test checks that they match the schema.

🤖 Drafted with AI assistance (Claude Code)

@dweindl dweindl self-assigned this Oct 15, 2026
@codecov-commenter

codecov-commenter commented Oct 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.50000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 77.77%. Comparing base (663b383) to head (a19daf4).

Files with missing lines Patch % Lines
petab/v2/core.py 80.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #547      +/-   ##
==========================================
+ Coverage   77.74%   77.77%   +0.03%     
==========================================
  Files          67       67              
  Lines        7702     7708       +6     
  Branches     1378     1380       +2     
==========================================
+ Hits         5988     5995       +7     
  Misses       1226     1226              
+ Partials      488      487       -1     

☔ 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.

@dweindl
dweindl marked this pull request as ready for review October 15, 2026 08:51
@dweindl
dweindl requested a review from a team as a code owner October 15, 2026 08:51

@dilpath dilpath left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good. Could also be covered by petab.v2.options but no need I think.

Comment thread petab/v2/core.py

# Omit empty optional entries. Required ones are kept even if empty.
for key in C.PROBLEM_CONFIG_OPTIONAL_KEYS:
# an empty `id` is invalid and must not be dropped silently

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Strange that the spec allows "empty" for the optional tables but not for the optional ID?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, still some inconsistencies there..

@dweindl

dweindl commented Oct 15, 2026

Copy link
Copy Markdown
Member Author

Could also be covered by petab.v2.options but no need I think.

Agreed

dweindl and others added 2 commits October 15, 2026 12:02
`ProblemConfig.to_yaml` wrote `condition_files: []`,
`experiment_files: []`, `mapping_files: []` and `extensions: {}` when
these were not set. They are optional in the PEtab v2 schema, so leave
them out. Required entries are still written even when empty, so that a
schema violation stays visible.

This affects `Problem.to_files` and `petab1to2`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add `PROBLEM_CONFIG_REQUIRED_KEYS`, `PROBLEM_CONFIG_OPTIONAL_KEYS` and
`PROBLEM_ID`, and use them in `ProblemConfig.to_yaml`. A test checks
that the lists match the PEtab v2 schema.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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