← Back to Pull requests

[ENH] Add augmentation support to `TslibDataModule` #2494

Open
unknown opened this pull request with 399 lines diff across 4 files
View on GitHub
unknown unknown commented on Nov 03, 2026 02:21 UTC
Author

Reference Issues/PRs

Fixes #2417. Split out of #2330.

What does this implement/fix? Explain your changes.

| File | What it contains |
|---|---|
| pytorch_forecasting/data/augmentation.py | New module: BaseAugmentation, resample_positions, a torch DTW core, the 8 per-sample transforms, the 6 label-guided transforms, and NeighbourIndex |
| tests/test_data/test_augmentation.py | New test module, 106 tests |
| pytorch_forecasting/data/data_module/_tslib_data_module.py | __getitem__ split into _slice_window / _augment / _assemble; the augmentation and augmentation_label parameters; train-only wiring in setup; _build_neighbour_index |
| pytorch_forecasting/data/__init__.py | Exports the 15 public names |
| docs/source/data_v2.rst | Autosummary entries and a line on augmentation in the D2 layer section |
| pytorch_forecasting/data/tests/test_tslib_data_module.py | One test pinning that the __getitem__ split is behaviour-preserving |

What should a reviewer concentrate their feedback on?

See #2417.

Did you add any tests for the change?

| Area | What is pinned |
|---|---|
| resample_positions | Continuous and target blocks interpolate; categorical codes snap to the nearest step; out-of-range positions clamp rather than wrap; the split lengths survive |
| Every transform | Changes the data; preserves all three block shapes; never mutates the input; reproducible for one seed and different across seeds |
| Time-axis alignment | After any resampling the categorical block still describes the same timestep as the continuous one — the guarantee resample_positions exists for |
| Per-transform behaviour | Scaling holds one factor per channel constant over time; SignFlip does not permute feature columns; Permutation is a true permutation of the original steps; TimeWarp shares one warp across channels; WindowSlice covers a sub-span |
| DTW core | Self-alignment is the diagonal; the path is monotone and covers both series end to end; the Sakoe-Chiba band constrains it; empty input raises; shape_dtw is not the pointwise distance |
| Train-only | The transform reaches train_dataset and no other split; default-off leaves every split unaugmented |
| Wiring | A single transform and a list are both accepted, and a list applies in order; the same index is resampled afresh on every access |
| Neighbour pool | Built only when a transform declares requires_neighbours; a neighbour always comes from a different series; the other-label draw really differs in label; a label covering one series raises when the index is built; as_array excludes the categorical block |
| Public API | All 14 transforms plus BaseAugmentation import from pytorch_forecasting.data |
| Through a real dataloader | An augmented batch collates and is finite, validation stays byte-identical to the unaugmented module, and seed_everything makes an epoch reproducible |

PR checklist

  • The PR title starts with either [ENH], [MNT], [DOC], or [BUG].

  • Added/modified tests

  • Used pre-commit hooks when committing to ensure that code is compliant with hooks.
  • Diff: 399 lines (+299 / -100) across 4 files Reviewer: phoeenniixx Review duration: 39732m
    All Vouch review confidence checks passed
    Residual risk 0.25 = Change Risk (0.43) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 399 lines diff across 4 files
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    42%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.358
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #2494"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 43.2% (MEDIUM) · Higher = larger blast radius
    43.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 43.0% · Lower = rushed or shallow review
    43.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 24.7% · Safe to merge
    24.7%