Skip to content

Fix spurious index column in v2 table round-trips - #542

Merged
dweindl merged 2 commits into
PEtab-dev:mainfrom
dweindl:fix_v2_index_column
Oct 14, 2026
Merged

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

Conversation

@dweindl

@dweindl dweindl commented Oct 14, 2026

Copy link
Copy Markdown
Member

from_df of the v2 parameter, measurement, observable and mapping tables unconditionally called reset_index(), which turned an unnamed index (e.g. the default RangeIndex from from_tsv) into an extra index column. That column was kept due to extra="allow" and written out again, adding another column on each load/save cycle. Now only named index levels are moved to columns.

Also:

  • accept empty observableParameters / noiseParameters strings, so that MeasurementTable.from_df(table.to_df()) works
  • don't modify the input DataFrame in ObservableTable.from_df (get_observable_df operates in place)

Fixes #541. Relates to #523.

🤖 Generated with Claude Code

`from_df` of the v2 parameter, measurement, observable and mapping
tables unconditionally called `reset_index()`, which turned an unnamed
index into an extra `index` column that was kept and written out.
Now only named index levels are moved to columns.

Also:
* accept empty `observableParameters` / `noiseParameters` strings, so
  `MeasurementTable.from_df(table.to_df())` works
* don't modify the input DataFrame in `ObservableTable.from_df`

Fixes PEtab-dev#541. Relates to PEtab-dev#523.

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

codecov-commenter commented Oct 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.58%. Comparing base (1c3d7b9) to head (472a9d1).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #542      +/-   ##
==========================================
+ Coverage   77.43%   77.58%   +0.15%     
==========================================
  Files          67       67              
  Lines        7670     7673       +3     
  Branches     1374     1374              
==========================================
+ Hits         5939     5953      +14     
+ Misses       1242     1231      -11     
  Partials      489      489              

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

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

Thanks!

Comment thread tests/v2/test_core.py
Comment on lines +116 to +119
df.index = [5, 7]
df_orig = df.copy()
table = table_cls.from_df(df)
assert_frame_equal(df, df_orig)

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.

What does this assert do? It looks like this must be equal because one is a copy of the other?

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.

This is related to the df = get_observable_df(df.copy()) line in petab/v2/core.py. Previously, from_df would mutated the input via get_observable_df.

@dweindl
dweindl merged commit 539333b into PEtab-dev:main Oct 14, 2026
7 checks passed
@dweindl
dweindl deleted the fix_v2_index_column branch October 14, 2026 21:22
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.

v2: table round-trip adds spurious index column

3 participants