Skip to content

v1: validate and consistently interpret estimate values - #650

Merged
dweindl merged 5 commits into
PEtab-dev:mainfrom
dweindl:v1_estimate_parsing
Dec 1, 2026
Merged

dweindl merged 5 commits into
PEtab-dev:mainfrom
dweindl:v1_estimate_parsing

Conversation

@dweindl

@dweindl dweindl commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

lint_problem crashed with ValueError instead of reporting invalid estimate values (e.g., "abc", empty cells) or non-numeric bounds, as the parameter table checks used int()/float() without catching errors. Also, estimate=0.5 was accepted, and string estimate values were interpreted differently by lint ("1" estimated) and by the rest of petab.v1 ("1" not estimated by, e.g., get_optimization_parameters).

Changes:

  • estimate values are parsed by a single function. Valid values are integers and floats equal to 0 or 1 (floats, because an empty cell makes pandas read the column as float) and the strings "0" and "1". Booleans, other strings such as "1.0" or "+1", and missing values are invalid.
  • All code in petab.v1 (and petab1to2) that decides whether a parameter is estimated uses the new _is_estimated, which does not modify the parameter table. Invalid values count as not estimated, except booleans, which are rejected by lint but still interpreted as 0/1 elsewhere for backwards compatibility.
  • Lint reports invalid estimate values and non-numeric lowerBound, upperBound, and nominalValue values as AssertionError naming the affected parameters. Numeric strings such as "0.1" are accepted for these columns. Non-numeric nominalValues of estimated parameters were not checked before.
  • check_parameter_bounds compares numeric values, so numeric-string bounds no longer raise TypeError.
  • check_parameter_bounds reports missing bounds of estimated parameters as such (previously "lowerBound greater than upperBound") and lists all affected parameters instead of only the first.

Converting numeric-string bounds and nominal values in non-lint code (e.g., Problem.lb_scaled, prior handling, sampling) is left for a follow-up; that code already failed on string bounds before this change.

Closes #641.

🤖 Generated with Claude Code

dweindl and others added 2 commits December 1, 2026 12:07
`lint_problem` crashed with `ValueError` instead of reporting invalid
`estimate` values (e.g., `"abc"`, empty cells) or non-numeric bounds,
since the parameter table checks used `int()`/`float()` without catching
errors. Also, `0.5` was accepted as `estimate`, and string `estimate`
values were interpreted differently by lint (`"1"` estimated) and by the
rest of `petab.v1` (`"1"` not estimated).

Now, `estimate` values are parsed by a single function: accepted are
integers and floats equal to 0 or 1 and the strings `"0"` and `"1"`.
All code that decides whether a parameter is estimated uses
`_is_estimated`, which does not modify the parameter table. Booleans
are rejected by lint, but still interpreted as 0/1 elsewhere for
backwards compatibility.

Lint now reports invalid `estimate` values and non-numeric
`lowerBound`, `upperBound`, and `nominalValue` values as
`AssertionError` naming the affected parameters. Numeric strings such
as `"0.1"` are accepted for these columns.

Closes PEtab-dev#641.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dweindl dweindl self-assigned this Dec 1, 2026
@codecov-commenter

codecov-commenter commented Dec 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.05882% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.20%. Comparing base (4aca22f) to head (8da2c7e).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
petab/v1/parameters.py 93.75% 1 Missing ⚠️
petab/v1/problem.py 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #650      +/-   ##
==========================================
+ Coverage   80.44%   81.20%   +0.75%     
==========================================
  Files          75       75              
  Lines        8596     8793     +197     
  Branches     1568     1608      +40     
==========================================
+ Hits         6915     7140     +225     
+ Misses       1191     1172      -19     
+ Partials      490      481       -9     

☔ 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 December 1, 2026 11:20
@dweindl
dweindl requested a review from a team as a code owner December 1, 2026 11:20
@dweindl
dweindl requested a review from PaulJonasJost December 1, 2026 11:20

@PaulJonasJost PaulJonasJost left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In general approved. If the to_numeric is possible, could vastly shorten the PR

Comment thread petab/v1/parameters.py Outdated
return list(parameter_df.index[_is_estimated(parameter_df)])


def _parse_float(value) -> float:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

As this seemed similar to #640, i asked claude briefly:
can most of these helpers be replaced with pd.to_numeric? With is_bool = values.map(lambda v: isinstance(v, bool | np.bool_)):

  • _parse_floats → pd.to_numeric(values, errors="coerce").astype(float).mask(is_bool). The only difference is "1_0", which float() accepts as 10.
  • _parse_estimate → the same, followed by .where(lambda x: x.isin([0, 1])).
  • _is_estimated → pd.to_numeric(df[ESTIMATE], errors="coerce").eq(1).fillna(False).astype(bool).

The only behaviour change for estimate is that numeric strings such as "1.0", "+1", "01", " 1" and "1e0" count as 1, where the current code accepts only "0" and "1". Is that strictness intended? If so, a small string check in lint could keep it, while allow_bool, the nested parser and the fast paths could still go.

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.

I would prefer being even more strict, but that is difficult to get into the current v1 code. From those examples, I would only find it reasonable to accept " 1" if we ignore extra whitespace everywhere.
We could argue about some individual cases to accept or not, but overall, the goal was to apply the same rules for the linter and the other consumers and not to introduce different conversion/acceptance rules.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

fair point, but perhaps we can add for those a small correction and still mainly use the pd.to_numeric? not a strong opinion, but i see opportunity to keep the code base smaller 🙈

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.

Saved 25 lines in ce0cb00

Comment thread petab/v1/priors.py
)
from .distributions import *
from .parameters import scale, unscale
from .parameters import _is_estimated, scale, unscale

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Since we import it here, should we make it a public function?

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.

No, it's still (package)private.

Comment thread petab/v1/lint.py
Numeric strings are accepted, see :func:`parameters._parse_float`.
"""
values = df[column]
present = values.notna() & ~values.isin([""])

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This together with the check in line 679 could produce a misleading error when only one value is "" correct? not sure this is intended.

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.

Old issue, but good catch. Fixed now.

Comment thread petab/v1/lint.py Outdated
is_estimated = parameters._is_estimated(parameter_df)
lower_bounds = parameters._parse_floats(parameter_df[LOWER_BOUND])
upper_bounds = parameters._parse_floats(parameter_df[UPPER_BOUND])
for (par_id, row), estimated, lb, ub in zip(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Since the masks are already column-wise, could the loop be replaced by filtering to estimated rows and checking with masks?

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.

Makes sense. Changed it. Now all errors of one type share a single error message.

dweindl and others added 3 commits December 1, 2026 14:52
Report missing bounds of estimated parameters explicitly, instead of as
`lowerBound` greater than `upperBound`. Check all parameters at once and
report all affected parameters.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replace the per-value parsers by `pd.to_numeric`. `estimate` still only
accepts the strings `"0"` and `"1"`. Numeric strings with underscores,
such as `"1_0"`, are no longer accepted as bounds or nominal values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Still needed for type annotations; removing it only went unnoticed on
Python >= 3.14, where annotations are evaluated lazily.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dweindl
dweindl added this pull request to the merge queue Dec 1, 2026
Merged via the queue into PEtab-dev:main with commit 560c374 Dec 1, 2026
8 checks passed
@dweindl
dweindl deleted the v1_estimate_parsing branch December 1, 2026 19:15
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.

v1 lint: invalid estimate or bounds values crash lint_problem

3 participants