Skip to content

Fix SMAPE handling of missing and zero forecasts - #286

Merged
Mariana Menchero García (MMenchero) merged 2 commits into
Nixtla:mainfrom
vgvr0:fix/smape-missing-zero
Oct 2, 2026
Merged

Mariana Menchero García (MMenchero) merged 2 commits into
Nixtla:mainfrom
vgvr0:fix/smape-missing-zero

Conversation

@vgvr0

@vgvr0 vgvr0 commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix SMAPE handling of zero and missing forecasts across pandas and Polars.

Previously, fill_null(0) conflated two different cases:

  • y = 0 and y_hat = 0, which should contribute zero error.
  • Missing forecasts, which should remain missing and be excluded from the mean.

This also produced different behavior between pandas and Polars.

Changes

  • Handle a zero SMAPE denominator explicitly as 0.0.
  • Preserve missing forecasts instead of turning them into perfect predictions.
  • Align pandas and Polars behavior.
  • Add regression tests covering:
    • 0/0
    • partially missing forecasts
    • completely missing forecasts
    • ordinary forecasts

Validation

  • tests/test_losses.py: 122 passed, 8 skipped
  • Full test suite: 1746 passed, 9 skipped
  • Coverage: 88.94%

Fixes #285

@MMenchero

Copy link
Copy Markdown
Contributor

Thank you for your contribution vgvr0.

@MMenchero
Mariana Menchero García (MMenchero) merged commit 1eb6101 into Nixtla:main Oct 2, 2026
17 of 18 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.

[losses] smape scores a missing forecast as a perfect 0, and on polars an exact 0 forecast of a 0 actual makes the series NaN

2 participants