Repository navigation
fix(core): unnamed-multiindex-roundtrip - #7680
Closed
dvvrtmshra wants to merge 1 commit into
Closed
dvvrtmshra wants to merge 1 commit into
dvvrtmshra wants to merge 1 commit into
Conversation
Contributor
|
Hi @dvvrtmshra, thanks for the PR, however this PR is superseded by #7762 because of the V5 file move. Closing as a duplicate. |
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.
Pull Request the OpenBB Platform
Description
Summary of the change/ bug fix.
df_to_basemodelfollowed bybasemodel_to_dfraised aKeyErrorwhen the DataFrame had an unnamed or partially namedMultiIndex. Unnamed levels are stored inmultiindex_namesasNone, butreset_index()turns them into columns namedlevel_0,level_1, etc., soset_indexcould not find them.This PR records the reset-index column names in a new
multiindex_columnsfield, separately from the original level names.basemodel_to_dfrebuilds the index from those columns and then restores the original level names (includingNone). Ifmultiindex_columnsis absent, it falls back to the previous behavior, so existing payloads and the fully named case are unaffected.Link # issue, if applicable.
Fixes #ISSUE_NUMBER
Screenshot of the feature or the bug before/after fix, if applicable.
N/A. Before/after is shown by the reproduction below.
Relevant motivation and context.
Round-tripping a DataFrame with an unnamed MultiIndex, which pandas produces by default from
MultiIndex.from_tuples,groupbyon multiple keys, etc., failed outright. Fully named MultiIndexes already worked.List any dependencies that are required for this change.
None.
How has this been tested?
test_multiindex_round_trip_unnamed_levels, inopenbb_platform/core/tests/app/test_utils.py, covering[None, None],["group", None], and[None, "id"]. Each case asserts the round-tripped DataFrame equals the original viapd.testing.assert_frame_equal.developcode with the reportedKeyErrorand pass with this change. All existing tests intest_utils.pystill pass.Reproduction:
Test configuration: Windows, Python 3.11.9, OpenBB installed from source via
dev_install.py.Checklist
feature/feature-nameorhotfix/hotfix-name.