Consistent zero-denominator handling for percentage and range metrics
Context
PR #3122 added a zero_division parameter to wmape, ope, arre, marre, and coefficient_of_variation, mirroring the scaled-metric work in #3059 (mase, msse, rmsse). Review feedback (thanks @jakubchlapek) converged on a cleaner, consistent design than the initial NaN-on-zero approach. This issue tracks completing that design across the percentage/range metric family.
Agreed design
A single shared helper handles every "divide a numerator by a possibly-zero denominator" case, distinguishing two sub-cases exactly as the existing _safe_scaled_divide already does:
- 0/0 (numerator 0 and denominator 0) → the metric's best score (a perfect forecast on a degenerate series):
0.0for percentage-error metrics,1.0for scaled-error metrics ("on par with naive"). The fill value is a helper parameter. - x/0 (numerator ≠ 0, denominator 0) →
np.nan. Filling with the best score here would mask a real miss. zero_division="raise"preserves the legacyValueError.
Rationale: the current PR fills every zero-denominator entry with NaN, which incorrectly scores a genuinely perfect forecast (e.g. ope on a series summing to zero with an identical prediction; arre/marre on a constant series predicted perfectly) as NaN instead of 0.0. sape/smape already encode the 0/0 → 0.0 convention, confirming it.
Scope
- Aggregate-denominator (this PR, #3122):
wmape,ope,arre,marre,coefficient_of_variation— switch to the unified helper withbest_score=0.0. (coefficient_of_variationisRMSE/mean, so0.0= perfect forecast — proposed, pending confirmation since its denominator can be negative.) - Already aligned:
sape/smapealready fill0/0 → 0.0inline and have nox/0case (the symmetric denominator is zero only when both actual and prediction are zero) — they need only the explicitzero_divisionknob for the"raise"option. - Element-wise denominator (deliberate / possibly follow-up):
ape,mapestill hard-raise if anyy_t == 0; their denominator is per-timestep, so they need element-wise handling, and relaxing MAPE's default is a larger behavioral change.
Implementation
Collapse _safe_pct_divide into _safe_scaled_divide (one helper, configurable 0/0 fill, with the warn/raise message parameterized so the scaled callers keep their existing strings), update the callers, add a 0/0 best-score test case, and fold the ope negative-sum test into test_ope(). Tracked by #3122.