Skip to content

Fix silent truncation crash for short forecast data#254

Open
Ayushhgit wants to merge 2 commits intomllam:mainfrom
Ayushhgit:fix-forecast-bounds
Open

Fix silent truncation crash for short forecast data#254
Ayushhgit wants to merge 2 commits intomllam:mainfrom
Ayushhgit:fix-forecast-bounds

Conversation

@Ayushhgit
Copy link
Copy Markdown

@Ayushhgit Ayushhgit commented Feb 25, 2026

Describe your changes

Summary of the changes:

  • Updated the n_forecast_steps bounds validation check inside WeatherDataset.__len__ to assert that the available forecast steps length can satisfy both the required autoregressive steps (ar_steps) and the required forcing steps (num_past_forcing_steps + num_future_forcing_steps).

Motivation and context:
Currently, len validates available data length against only the AR steps, completely omitting the extra forcing padding limits. If your datastore's forecast duration is slightly shorter than the maximum forcing offset boundaries, xarray.isel silently truncates the dimension slices instead of failing. When PyTorch Lightning attempts to collate the slices, the batch tensors have randomly mismatched sequence dimensions leading to incredibly cryptic runtime shape mismatch crashes. This PR safely prevents the silent truncation at initialization.

Dependencies:
None

Issue Link

N/A

Type of change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📖 Documentation (Addition or improvements to documentation)

Checklist before requesting a review

  • My branch is up-to-date with the target branch - if not update your fork with the changes from the target branch (use pull with --rebase option if possible).
  • I have performed a self-review of my code
  • For any new/modified functions/classes I have added docstrings that clearly describe its purpose, expected inputs and returned values
  • I have placed in-line comments to clarify the intent of any hard-to-understand passages of my code
  • I have updated the README to cover introduced code changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have given the PR a name that clearly describes the change, written in imperative form (context).
  • I have requested a reviewer and an assignee (assignee is responsible for merging). This applies only if you have write access to the repo, otherwise feel free to tag a maintainer to add a reviewer and assignee.

Checklist for reviewers

Each PR comes with its own improvements and flaws. The reviewer should check the following:

  • the code is readable
  • the code is well tested
  • the code is documented (including return types and parameters)
  • the code is easy to maintain

Author checklist after completed review

  • I have added a line to the CHANGELOG describing this change, in a section
    reflecting type of change (add section where missing):
    • added: when you have added new functionality
    • changed: when default behaviour of the code has been changed
    • fixes: when your contribution fixes a bug
    • maintenance: when your contribution is relates to repo maintenance, e.g. CI/CD or documentation

Checklist for assignee

  • PR is up to date with the base branch
  • the tests pass
  • (if the PR is not just maintenance/bugfix) the PR is assigned to the next milestone. If it is not, propose it for a future milestone.
  • author has added an entry to the changelog (and designated the change as added, changed, fixed or maintenance)
  • Once the PR is ready to be merged, squash commits and merge the PR.

@leifdenby
Copy link
Copy Markdown
Member

Good catch @Ayushhgit! Could you add a test to confirm your implementation works please? thank you :)

@Ayushhgit
Copy link
Copy Markdown
Author

@leifdenby , I have added a test function to confirm that my implementation works.

@sadamov sadamov added the bug Something isn't working label Mar 1, 2026
@sadamov
Copy link
Copy Markdown
Collaborator

sadamov commented Mar 8, 2026

@Ayushhgit I must admit, I did not remember this PR and already reviewed this more recent one here: #312 It solves the same issue. If you don't mind, would you head over there and discuss the implementation. Especially the tests your implemented are a bit different.
Apologies!

@sadamov sadamov added the duplicate This issue or pull request already exists label Mar 8, 2026
@kshirajahere
Copy link
Copy Markdown
Contributor

@sadamov One thing to note for coordination: PR #254 overlaps with the forecast-mode forcing-horizon validation part of #312. Not being defensive but #312 is still broader in scope, since it also includes the analysis-side out-of-bounds / indexing-robustness changes from #311.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working duplicate This issue or pull request already exists

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants