You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: extend zero_division parameter to percentage and range-based metrics
Percentage and range-based metrics (`wmape`, `ope`, `arre`, `marre`,
`coefficient_of_variation`) previously either raised a hard `ValueError`
or silently returned `nan`/`inf` when their denominator was zero. This
made batch evaluation pipelines brittle for constant or all-zero
components.
Mirrors the `zero_division` design introduced in #3059 for the scaled
error family: `"warn"` (default) returns `np.nan` and emits a warning,
`"raise"` preserves the legacy `ValueError`. A new `_safe_pct_divide`
helper sits next to `_safe_scaled_divide`; the two differ only in fill
semantics — percentage metrics multiply the ratio by 100 so a `1.0`
fill for the 0/0 case (the scaled-metric "on par with naive") would
surface as `100 %` error and be misleading, hence `np.nan` instead.
Two adjacent bugs surface and are fixed in the same change:
* `ope` previously checked `sum > 0` and rejected `actual_series` with
a strictly negative sum (e.g. financial return series). The check
is now `sum != 0` via the helper.
* `wmape`'s docstring claimed `ValueError if actual_series contains
some zeros`, but the implementation divides by `sum(|y_true|)` and
only the all-zero case ever triggered the path. Docstring corrected.
The CHANGELOG entry for the parameter addition carries the breaking-
change marker per the convention discussed in #3080 (the post-mortem
on #3059), since the default behavior flips from raising to warning.
Adds a parametrized regression test covering all five metrics and an
explicit OPE-with-negative-sum test. Existing `test_ope_zero` and the
arre/marre legacy raise check are updated to opt into the legacy
behavior with `zero_division="raise"`.
Copy file name to clipboardExpand all lines: CHANGELOG.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,12 +15,14 @@ but cannot always guarantee backwards compatibility. Changes that may **break co
15
15
- Added `use_longer_projection_head` to `TimesFM2p5Model` to enable longer non-autoregressive prediction horizons (up to 1024 steps for `output_chunk_length + output_chunk_shift`). [#3121](https://github.com/unit8co/darts/pull/3121) by [Zhihao Dai](https://github.com/daidahao).
16
16
-`TimeSeries.from_dataframe()` now supports time columns of type `pl.Date` for `polars.DataFrame`. [#3124](https://github.com/unit8co/darts/pull/3124) by [Dennis Bader](https://github.com/dennisbader)
17
17
- Custom encoders now support functions that return multiple components. Simply pass such a function via the `"custom"` encoder key in the `add_encoders` model input parameter. [#3069](https://github.com/unit8co/darts/pull/3069) by [Moritz Waldleben](https://github.com/mwaldleben).
18
+
- 🔴 Percentage and range-based metrics (`wmape`, `ope`, `arre`, `marre`, `coefficient_of_variation`) now expose a `zero_division` parameter (mirroring [#3059](https://github.com/unit8co/darts/pull/3059)) controlling the behavior when the denominator is zero: `"warn"` (default) returns `np.nan` and emits a warning, `"raise"` preserves the legacy `ValueError`. [#3122](https://github.com/unit8co/darts/pull/3122) by [Mahimn](https://github.com/mahimn01).
18
19
19
20
**Fixed**
20
21
21
22
- Fixed `_ScaledDotProductAttention` float16 overflow in `masked_fill` under mixed precision training. [#3087](https://github.com/unit8co/darts/pull/3087) by [Robert Ruidisch](https://github.com/robrui).
22
23
- Fixed a bug in `TimeSeries.quantile()` where the output dtype did not match the input series dtype for dtypes `float32` or `float16`. Now the dtype is correctly propagated. [#3124](https://github.com/unit8co/darts/pull/3124) by [Dennis Bader](https://github.com/dennisbader)
23
24
- Optuna integration's `PyTorchLightningPruningCallback` for hyperparameter optimization of torch models is now natively available in Darts via `darts.utils.callbacks`. [#3114](https://github.com/unit8co/darts/pull/3114) by [Jakub Chłapek](https://github.com/jakubchlapek).
25
+
- Fixed `ope` to accept `actual_series` with a strictly negative sum; the previous `sum > 0` check incorrectly rejected valid inputs such as financial return series. Also corrected the `wmape` docstring which inaccurately claimed it raised on zeros in `actual_series`. [#3122](https://github.com/unit8co/darts/pull/3122) by [Mahimn](https://github.com/mahimn01).
0 commit comments