Repository navigation
[BugFix] #7672-Preserve unnamed MultiIndex levels in DataFrame round-trip. - #7762
Merged
deeleeramone merged 5 commits intoOct 24, 2026
Merged
Conversation
12 of 21 tasks
dlee-bq
requested changes
Oct 19, 2026
dlee-bq
left a comment
Contributor
There was a problem hiding this comment.
Thanks for the PR @amirani8137, I have left a couple of comments in the changed files for your consideration.
dlee-bq
approved these changes
Oct 24, 2026
dlee-bq
left a comment
Contributor
There was a problem hiding this comment.
Thanks for your help! The test failures are unrelated, and stem from an upstream change to FastAPI defaults.
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_basemodel→basemodel_to_dfraised aKeyErrorfor a DataFrame with an unnamed or partially namedMultiIndex.df_to_basemodelstored the original level names (Nonefor unnamed levels), butreset_index()moves those levels into columns namedlevel_0,level_1, ….basemodel_to_dfthen calledset_indexwith the storedNonenames, and no columns have those names.The fix records the actual column names created by
reset_index()in a newmultiindex_columnsfield.basemodel_to_dfsets the index from those columns and then restores the original level names, includingNone. Records withoutmultiindex_columns, such as data created before this change or byapp/model/example.py, still go through the existing path.Link # issue, if applicable.
Fixes [Bug] DataFrame round-trip fails for unnamed MultiIndex levels #7672
Screenshot of the feature or the bug before/after fix, if applicable.
Relevant motivation and context.
A DataFrame with an unnamed or partially named
MultiIndexshould survive the round trip with its index values and level names intact.List any dependencies that are required for this change.
None
How has this been tested?
Added
test_multiindex_round_triptoopenbb_platform/core/tests/app/test_utils.py, parametrized over fully named, fully unnamed, first-level-unnamed and second-level-unnamed indexes. Each case checks that the index type, level names, index values and column data match after the round trip.Without the fix, the three unnamed/partially named cases fail with the
KeyErrorreported in the issue. With the fix, all 48 tests intest_utils.pypass.To reproduce:
pytest openbb_platform/core/tests/app/test_utils.pyConfiguration: Python 3.11.9, pandas 3.0.6, pydantic 2.13.5, Windows 11.
Ensure all unit and integration tests pass.
If you modified/added command(s):
If a new provider was introduced or a new fetcher was added to an existing provider:
If a new provider or extension was added:
Checklist
feature/feature-nameorhotfix/hotfix-name.