Skip to content

Fix TslibDataModule setup re-entrancy guards#2245

Open
Ajeem-git wants to merge 3 commits intosktime:mainfrom
Ajeem-git:issue-2218-tslib-setup-guard
Open

Fix TslibDataModule setup re-entrancy guards#2245
Ajeem-git wants to merge 3 commits intosktime:mainfrom
Ajeem-git:issue-2218-tslib-setup-guard

Conversation

@Ajeem-git
Copy link
Copy Markdown

Summary

  • reuse the original randomized split indices when setup() is called repeatedly
  • check the actual dataset attributes instead of nonexistent private names before rebuilding datasets
  • add a regression test covering repeated setup(stage="fit") calls

Testing

  • python3.11 -m py_compile pytorch_forecasting/data/_tslib_data_module.py pytorch_forecasting/data/tests/test_tslib_data_module.py

Closes #2218

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 30, 2026

Codecov Report

❌ Patch coverage is 45.23810% with 23 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@af9b14f). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...h_forecasting/data/tests/test_tslib_data_module.py 0.00% 20 Missing ⚠️
pytorch_forecasting/data/_tslib_data_module.py 86.36% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2245   +/-   ##
=======================================
  Coverage        ?   86.53%           
=======================================
  Files           ?      166           
  Lines           ?     9784           
  Branches        ?        0           
=======================================
  Hits            ?     8467           
  Misses          ?     1317           
  Partials        ?        0           
Flag Coverage Δ
cpu 86.53% <45.23%> (?)
pytest 86.53% <45.23%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Meet-Ramjiyani-10
Copy link
Copy Markdown
Contributor

Nice work !
Verified the attribute names are now correct (train_dataset vs _train_dataset).

One question: Should stage="test" and stage="predict" also have re-entrancy guards? Currently only "fit" is protected.

Otherwise LGTM.

@Ajeem-git
Copy link
Copy Markdown
Author

Good catch. test was already guarded with a check that only creates the dataset once, but predict was not consistent with that yet. I pushed a small follow-up to make predict re-entrant as well, and added a regression test for repeated setup(stage="predict") calls.

@Meet-Ramjiyani-10
Copy link
Copy Markdown
Contributor

Cool! The predict stage guard and regression test look correct. LGTM

One small note for future consistency: the test stage still uses the old _test_dataset guard (if not hasattr(self, "_test_dataset"):). Since _test_dataset is never assigned, this guard doesn’t actually prevent re-creation. Might be worth a follow-up PR to align it with the fit/predict pattern. Not a blocker for this PR though.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TslibDataModule.setup() re-entrancy guard checks wrong attribute name, causing full dataset recreation on every call

2 participants