Skip to content

[BugFix] #7672-Preserve unnamed MultiIndex levels in DataFrame round-trip. - #7762

Merged
deeleeramone merged 5 commits into
openbq-org:developfrom
amirani8137:fix/7672-multiindex-round-trip
Oct 24, 2026
Merged

deeleeramone merged 5 commits into
openbq-org:developfrom
amirani8137:fix/7672-multiindex-round-trip

Conversation

@amirani8137

Copy link
Copy Markdown
Contributor

Pull Request the OpenBB Platform

Description

  • Summary of the change/ bug fix.
    df_to_basemodel → basemodel_to_df raised a KeyError for a DataFrame with an unnamed or partially named MultiIndex. df_to_basemodel stored the original level names (None for unnamed levels), but reset_index() moves those levels into columns named level_0, level_1, …. basemodel_to_df then called set_index with the stored None names, and no columns have those names.

    The fix records the actual column names created by reset_index() in a new multiindex_columns field. basemodel_to_df sets the index from those columns and then restores the original level names, including None. Records without multiindex_columns, such as data created before this change or by app/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 MultiIndex should 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_trip to openbb_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 KeyError reported in the issue. With the fix, all 48 tests in test_utils.py pass.

  • To reproduce: pytest openbb_platform/core/tests/app/test_utils.py

  • Configuration: 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):

    • Ensure the command(s) execute with the expected output.
      • API.
      • Python Interface.
    • If applicable, please add new tests for the command (see CONTRIBUTING.md to leverage semi-automated testing).
  • If a new provider was introduced or a new fetcher was added to an existing provider:

    • Ensure the existing tests pass.
    • Ensure the new provider and/or fetcher is stable and usable.
    • If applicable, please add new tests for the provider and/or fetcher (see CONTRIBUTING.md to leverage semi-automated testing).
  • If a new provider or extension was added:

Checklist

  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have adhered to the GitFlow naming convention and my branch name is in the format of feature/feature-name or hotfix/hotfix-name.
  • I ensure that I am following the CONTRIBUTING guidelines.

@CLAassistant

CLAassistant commented Oct 10, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@dlee-bq dlee-bq mentioned this pull request Oct 18, 2026
12 of 21 tasks

@dlee-bq dlee-bq left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @amirani8137, I have left a couple of comments in the changed files for your consideration.

Comment thread openbb_platform/core/tests/app/test_utils.py
Comment thread openbb_platform/core/openbb_core/app/utils/__init__.py Outdated

@dlee-bq dlee-bq left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your help! The test failures are unrelated, and stem from an upstream change to FastAPI defaults.

@deeleeramone
deeleeramone added this pull request to the merge queue Oct 24, 2026
Merged via the queue into openbq-org:develop with commit 7df7d0c Oct 24, 2026
42 checks passed
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.

[Bug] DataFrame round-trip fails for unnamed MultiIndex levels

4 participants