From 00687d459e601f2f54d94629a80b27f0287feb7f Mon Sep 17 00:00:00 2001 From: jbbqqf Date: Sun, 10 May 2026 00:32:15 +0200 Subject: [PATCH] fix(examples): handle NaNs in 14-transfer-learning air dataset (#2752) The transfer-learning notebook fails on the air dataset because the raw carrier_passengers.csv contains gaps that survive longest_contiguous_slice() (e.g. zero-rows that the slice helper does not treat as missing). The resulting NaNs propagate into model training and produce SMAPE = NaN errors, as reported in #2752. Fix: call fill_missing_values(series, fill="auto") inside load_air() right after longest_contiguous_slice(), with an inline comment pointing at the issue so a future reader doesn't have to dig through history. Imports the helper from darts.utils.missing_values. Maintainer @dennisbader acknowledged in #2752 that the notebook needs refactoring (it's one of the only ones that isn't tested in CI because it's slow); this is the smallest possible change that unblocks users running the example end-to-end. CHANGELOG entry under Unreleased > Fixed. Refs: https://github.com/unit8co/darts/issues/2752 Co-Authored-By: Claude Opus 4.7 --- CHANGELOG.md | 2 ++ examples/14-transfer-learning.ipynb | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a47a2faaaa..81a6981b8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ but cannot always guarantee backwards compatibility. Changes that may **break co **Fixed** +- Fixed `examples/14-transfer-learning.ipynb` raising a NaN error on the `air` dataset: the `load_air()` helper now calls `fill_missing_values(..., fill="auto")` after `longest_contiguous_slice()` to handle residual gaps in the raw `carrier_passengers.csv`. Closes [#2752](https://github.com/unit8co/darts/issues/2752). + **Dependencies** ### For developers of the library: diff --git a/examples/14-transfer-learning.ipynb b/examples/14-transfer-learning.ipynb index 579e6a5521..089e9e5bec 100644 --- a/examples/14-transfer-learning.ipynb +++ b/examples/14-transfer-learning.ipynb @@ -130,7 +130,8 @@ " RandomForestModel,\n", " Theta,\n", ")\n", - "from darts.utils.losses import SmapeLoss" + "from darts.utils.losses import SmapeLoss\n", + "from darts.utils.missing_values import fill_missing_values" ] }, { @@ -244,6 +245,11 @@ " series = series.longest_contiguous_slice()\n", " except Exception:\n", " continue\n", + " # Fill any residual missing values inside the chosen slice. The raw\n", + " # carrier_passengers.csv occasionally has gaps that survive the\n", + " # longest_contiguous_slice() call (e.g. zero-rows), which produce NaNs\n", + " # downstream and break model training. See issue #2752.\n", + " series = fill_missing_values(series, fill=\"auto\")\n", " # remove static covariates\n", " series = series.with_static_covariates(None)\n", " # remove short series\n",