Skip to content

fix(base): ignore unused alignment levels - #914

Open
JohnDReynolds wants to merge 1 commit into
polakowo:masterfrom
JohnDReynolds:fix/base/observed-alignment-keys
Open

JohnDReynolds wants to merge 1 commit into
polakowo:masterfrom
JohnDReynolds:fix/base/observed-alignment-keys

Conversation

@JohnDReynolds

Copy link
Copy Markdown
Contributor

Summary

Currently, filtering a MultiIndex can leave unused labels in its levels. Aligning prices for assets A and B to a filtered parameter grid can then raise ValueError solely because an unused C remains in the grid's metadata.

This PR fixes that by checking observed level labels and preserving normal ValueError rejection for empty sources. Existing complete-key and duplicate-source checks remain in place.

Benefit and scope: Allows filtered parameter grids to align through the index helper, .vbt.align_to and broadcasting with a small correction to the existing alignment helper.

Validation

Regression evidence

A grid filtered from assets A, B and C to A and B now aligns to the expected price columns even though C remains in its metadata. Regressions check the complete values and labels through .vbt.align_to and broadcasting on both rows and columns. Coverage also includes reordered and repeated keys, categorical labels combined with missing keys, unchanged inputs, and rejection of absent source keys. Empty sources reject unmatchable target keys with ValueError, while valid missing-key and empty-target cases remain covered. All 26 focused cases and the complete base test module (380 tests) pass.

Checks

  • Focused regression: 26 passed with RuntimeWarnings treated as errors.
  • Complete affected subsystem: pytest tests/test_base.py: 380 passed, with one existing column-orientation UserWarning.
  • Final full suite: pytest tests/: 1,938 passed and 2 skipped on the final amended commit.
  • Static, documentation, API, dependency, or build checks: Changed functions match the repository's formatting conventions and pass compilation and whitespace checks. No new Python files or packaging changes.

AI use

  • Tools and models: OpenAI Codex, using GPT-6.1 Sol.
  • What AI did: Used proprietary workflows tailored to this repository to reproduce the alignment failure, implement the level-admission correction and regression tests, check native pandas behavior and public consumers, measure resource impact, and prepare this description.
  • Human review before submission: I personally reviewed all changes, weighing the benefits against complexity and maintenance burden. My review draws on 40 years of software development experience in the investment management industry.

This branch has not been deployed

No deployments
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