Fix TypeError when timesteps list has a gap in blending.steps.forecast#560
Open
Yuxiang-Ren-HUB wants to merge 1 commit into
Open
Fix TypeError when timesteps list has a gap in blending.steps.forecast#560Yuxiang-Ren-HUB wants to merge 1 commit into
Yuxiang-Ren-HUB wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Calling
pysteps.blending.steps.forecast()with a sparsetimestepslist that has a gap (e.g.[1, 3], skipping2) raises:at
self.__state.final_blended_forecast[j].extend(...)inside__blended_nowcast_main_loop.Root cause
In
StepsBlendingNowcaster.__blended_nowcast_main_loop,worker(j)buildsfinal_blended_forecast_single_memberinsidefor t_sub in self.__state.subtimesteps:, but the line that stores it intofinal_blended_forecast_all_members_one_timestep[j]is indented one level too deep — inside that sameforloop instead of after it:When a requested
timestepslist has a gap,nowcast_utils.binned_timestepsproduces an empty bin for the skipped native step, soself.__state.subtimesteps == []at that outer step. Thefor t_sub in []:loop body then never runs, so the assignment never happens, andfinal_blended_forecast_all_members_one_timestep[j]is left at its initial value ofNone. That later gets passed to.extend(None).Note the two existing list-
timestepscases intest_blending_steps.pydon't actually exercise this:[1, 2, 3]has no gap, and the other[1, 3]case useszero_radar=True, zero_nwp=True, which takes an early-exit shortcut that skips the main loop entirely.Fix
Dedent the assignment one level so it runs once per ensemble member after the
subtimestepsloop finishes, regardless of whether that loop ran zero, one, or more iterations — matching the intent of "whatever this member produced at this outer step, even if that's nothing."Testing
timesteps=[1, 3]with non-zero radar/NWP precipitation (the two existing conditions needed to hit this bug at once).pysteps/tests/test_blending_steps.pysuite: 59 passed (58 existing + 1 new).black --checkpasses with no formatting changes needed.