Skip to content

fix: guard against all-NA scores in calc_correlations#316

Open
drussellmrichie wants to merge 2 commits intolarsiusprime:masterfrom
drussellmrichie:fix/calc-correlations-all-na
Open

fix: guard against all-NA scores in calc_correlations#316
drussellmrichie wants to merge 2 commits intolarsiusprime:masterfrom
drussellmrichie:fix/calc-correlations-all-na

Conversation

@drussellmrichie
Copy link
Copy Markdown

Problem

calc_correlations crashes with a KeyError or ValueError on .idxmin() when the computed score Series is all-NA. This occurs when there are too few samples to compute meaningful correlations (e.g. very small model groups or sparse data).

Fix

Add an early break when score.isna().all() is detected, exiting the variable-dropping loop gracefully instead of crashing.

Note: this branch also includes the fix from #315 (fix/tuning-min-samples-cv), on which it stacks.

Russell Richie and others added 2 commits March 27, 2026 13:19
When a model group has very few training samples (e.g. sparse commercial
or post-valuation sub-models), KFold raises ValueError if n_splits
exceeds the number of rows. Cap n_splits at len(X) and return a penalty
MAPE of 1.0 when fewer than 2 samples are available, so Optuna can
still complete gracefully.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When a model group has very few sales (e.g. vacant land with 9 records),
pandas' idxmin() raises ValueError('Encountered all NA values') instead
of returning NaN as in older pandas versions. Break out of the variable
elimination loop early when all scores are NA so downstream code is
unaffected.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

Thank you for your contribution.
Please sign our CLA at the following link:
Click here to sign the CLA.
A maintainer will verify your signature and confirm it here by commenting with the following sentence:


I affirm that this contributor has signed the CLA


Russell Richie seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

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