Skip to content

fix: parser mutates caller's DataFrame index name#656

Open
ecomodeller wants to merge 2 commits into
mainfrom
fix-vertical-parser-mutates-input
Open

fix: parser mutates caller's DataFrame index name#656
ecomodeller wants to merge 2 commits into
mainfrom
fix-vertical-parser-mutates-input

Conversation

@ecomodeller
Copy link
Copy Markdown
Member

@ecomodeller ecomodeller commented May 18, 2026

_parse_vertical_input set data.index.name = "time" on a column-sliced view of the caller's DataFrame (_vertical.py:135). Pandas shares the Index object between a column slice and its source, so the rename leaked back: a caller's df.index.name flipped from None to "time" after constructing either VerticalObservation or VerticalModelResult.

Fix: rewrite as data.rename_axis("time").to_xarray(), which returns a new DataFrame and leaves the caller's index untouched.

The first commit adds regression tests for both classes pinning the non-mutation contract; the second applies the parser fix.

…ating input DataFrame

Both classes call _parse_vertical_input, which currently sets
data.index.name = "time" on a column-sliced view of the caller's
DataFrame. Because pandas shares the Index object between a column slice
and its source, this mutation leaks back to the caller — observed as
df.index.name flipping from None to "time" after construction.

These tests pin the contract that construction is non-mutating. They are
expected to fail until the parser is fixed in a follow-up commit.
Replace the in-place `data.index.name = "time"` with `rename_axis("time")`,
which returns a new DataFrame. Pandas shares the Index object between a
column slice and its source, so the previous code leaked the rename back
to the caller.
@ecomodeller ecomodeller marked this pull request as ready for review May 18, 2026 16:24
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.

1 participant