From efa4b1a80efa8cd70f35d2cdd5e61272a1ba8a02 Mon Sep 17 00:00:00 2001 From: rencheng Date: Tue, 14 Jul 2026 23:59:52 +0800 Subject: [PATCH] Fix TypeError when timesteps list has a gap in blending.steps.forecast final_blended_forecast_all_members_one_timestep[j] was assigned inside the `for t_sub in subtimesteps:` loop, so when subtimesteps is empty (a bin with no requested output, e.g. the skipped step 2 in timesteps=[1, 3]) the assignment never ran and the value stayed at its initial None. That later hit `self.__state.final_blended_forecast[j].extend(None)`, raising "TypeError: 'NoneType' object is not iterable". Dedent the assignment one level so it runs once per member after the subtimesteps loop completes, whether or not that loop ran at all. Added a regression test (timesteps=[1, 3] with non-zero radar/NWP precip) -- the two existing list-timesteps test cases didn't actually exercise this path: [1, 2, 3] has no gap, and the other [1, 3] case uses zero precipitation, which takes an early-exit shortcut that skips the main loop entirely. --- pysteps/blending/steps.py | 6 +++--- pysteps/tests/test_blending_steps.py | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pysteps/blending/steps.py b/pysteps/blending/steps.py index 2d153510..2e57b26b 100644 --- a/pysteps/blending/steps.py +++ b/pysteps/blending/steps.py @@ -711,9 +711,9 @@ def worker(j): ) ) - final_blended_forecast_all_members_one_timestep[j] = ( - final_blended_forecast_single_member - ) + final_blended_forecast_all_members_one_timestep[j] = ( + final_blended_forecast_single_member + ) dask_worker_collection = [] diff --git a/pysteps/tests/test_blending_steps.py b/pysteps/tests/test_blending_steps.py index abfa5522..ea67bf12 100644 --- a/pysteps/tests/test_blending_steps.py +++ b/pysteps/tests/test_blending_steps.py @@ -17,6 +17,10 @@ (1, 3, 4, 8,'steps', None, "mean", False, "spn", True, 4, False, False, 0, True, None, None, None), (1, 3, 4, 8,'steps', None, "cdf", False, "spn", True, 4, False, False, 0, False, None, None, None), (1, [1, 2, 3], 4, 8,'steps', None, "cdf", False, "spn", True, 4, False, False, 0, False, None, None, None), + # Regression test for a gap in the timesteps list (e.g. [1, 3] skips 2): this used to raise + # "TypeError: 'NoneType' object is not iterable" because the bin for the skipped step never + # got a value written to final_blended_forecast_all_members_one_timestep. + (1, [1, 3], 4, 8,'steps', None, "cdf", False, "spn", True, 4, False, False, 0, False, None, None, None), (1, 3, 4, 8,'steps', "incremental", "cdf", False, "spn", True, 4, False, False, 0, False, None, None, None), (1, 3, 4, 6,'steps', "incremental", "cdf", False, "bps", True, 4, False, False, 0, False, None, None, None), (1, 3, 4, 6,'steps', "incremental", "cdf", False, "bps", False, 4, False, False, 0, False, None, None, None),