fix: parser mutates caller's DataFrame index name#656
Open
ecomodeller wants to merge 2 commits into
Open
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
_parse_vertical_inputsetdata.index.name = "time"on a column-sliced view of the caller's DataFrame (_vertical.py:135). Pandas shares theIndexobject between a column slice and its source, so the rename leaked back: a caller'sdf.index.nameflipped fromNoneto"time"after constructing eitherVerticalObservationorVerticalModelResult.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.