Fix MeanEstimator to ignore NaNs in training data - #3329
Open
SalahnAI wants to merge 1 commit into
Open
Conversation
A single NaN in any training series caused MeanEstimator to produce all-NaN forecasts, because the per-timestep mean over series was computed with ndarray.mean. Use np.nanmean instead, consistent with MeanPredictor and MovingAveragePredictor in the same module, and add tests for MeanEstimator (previously untested), including the NaN case. Fixes awslabs#2175
SalahnAI
force-pushed
the
fix/mean-estimator-ignore-nan
branch
from
July 29, 2026 15:04
0901f07 to
70895f5
Compare
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.
Description
A single NaN anywhere in the training data caused
MeanEstimatorto produce all-NaN forecasts for every series, because the per-timestep mean over series is computed withndarray.mean. As reported in #2175, one missing value in one series poisons all metrics for the whole backtest.This PR switches the computation to
np.nanmean, which is already the convention used byMeanPredictorandMovingAveragePredictorin the same module, soMeanEstimatornow behaves consistently with its neighbors.It also adds tests for
MeanEstimator(previously untested), including the NaN cases: a partially-NaN series and an all-NaN series.Fixes #2175
Testing
pytest test/model/trivial/— 35 passed (4 new).By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.