Skip to content

Commit 337c959

Browse files
dweindlclaude
andcommitted
Add options to omit empty or default columns from v2 tables
Converting PEtab v2 tables to DataFrames or TSV files currently always includes all standard columns, even if they are empty in every row. Add `TableColumns` modes `all` (default, current behavior), `non_empty`, and `non_default` to select the columns to include. Required columns (`C.*_DF_REQUIRED_COLS`) are always included. The mode can be passed to `to_df`, `to_tsv`, and `Problem.to_files`, or set via `petab.v2.set_options` or temporarily via `petab.v2.option_context`, which also applies to `Problem.*_df`. Also add the `parameterName` column as `Parameter.name`, add `nominalValue` to the required parameter table columns as in the spec, and make `to_df` work for empty parameter, observable, and measurement tables. Closes #523. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 6278958 commit 337c959

7 files changed

Lines changed: 445 additions & 21 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
Use `petab.v1.<name>` instead, e.g., `import petab.v1 as petab`.
1313
`import petab` no longer imports `petab.v1`.
1414
(by @dweindl in https://github.com/PEtab-dev/libpetab-python/pull/538)
15+
* `petab.v2.Parameter` has a new `name` field for the `parameterName` column,
16+
which was previously stored as an extra attribute `parameterName`.
17+
`BaseTable` subclasses now implement `_to_df` instead of `to_df`.
18+
(by @dweindl in https://github.com/PEtab-dev/libpetab-python/pull/543)
1519

1620
**Fixes**
1721
* `get_model_for_condition` no longer turns rate-rule targets that are
@@ -37,13 +41,21 @@
3741
* `petab.v2.ProblemConfig.to_yaml` no longer writes empty optional entries
3842
(`condition_files`, `experiment_files`, `mapping_files`, `extensions`)
3943
(by @dweindl in https://github.com/PEtab-dev/libpetab-python/pull/547)
44+
* `to_df` no longer fails for empty v2 parameter, observable and measurement
45+
tables
46+
(by @dweindl in https://github.com/PEtab-dev/libpetab-python/pull/543)
4047

4148
**Features**
4249
* `petab1to2` and `petab_files_1to2` can skip validation via `validate=False`
4350
(by @FFroehlich in https://github.com/PEtab-dev/libpetab-python/pull/534)
4451
* Added `petab.v2.C.PROBLEM_CONFIG_REQUIRED_KEYS` and
4552
`petab.v2.C.PROBLEM_CONFIG_OPTIONAL_KEYS`
4653
(by @dweindl in https://github.com/PEtab-dev/libpetab-python/pull/547)
54+
* PEtab v2 tables can omit empty columns or columns at their default values
55+
via `to_df(columns=...)`, `to_tsv(columns=...)` and
56+
`Problem.to_files(columns=...)`, or globally via `petab.v2.set_options` and
57+
`petab.v2.option_context`
58+
(by @dweindl in https://github.com/PEtab-dev/libpetab-python/pull/543)
4759

4860
## 0.9 series
4961

‎doc/modules.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@ API Reference
3838
petab.v2.extensions
3939
petab.v2.lint
4040
petab.v2.models
41+
petab.v2.options
4142
petab.v2.petab1to2

‎petab/v2/C.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
MEASUREMENT_DF_REQUIRED_COLS = [
4646
OBSERVABLE_ID,
4747
EXPERIMENT_ID,
48-
MEASUREMENT,
4948
TIME,
49+
MEASUREMENT,
5050
]
5151

5252
#: Optional columns of measurement table
@@ -91,13 +91,13 @@
9191
PARAMETER_ID,
9292
LOWER_BOUND,
9393
UPPER_BOUND,
94+
NOMINAL_VALUE,
9495
ESTIMATE,
9596
]
9697

9798
#: Optional columns of parameter table
9899
PARAMETER_DF_OPTIONAL_COLS = [
99100
PARAMETER_NAME,
100-
NOMINAL_VALUE,
101101
PRIOR_DISTRIBUTION,
102102
PRIOR_PARAMETERS,
103103
]

‎petab/v2/__init__.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@
3737
)
3838
from .lint import lint_problem # noqa: F401
3939
from .models import MODEL_TYPE_PYSB, MODEL_TYPE_SBML, Model # noqa: F401
40+
from .options import *

0 commit comments

Comments
 (0)