Skip to content

[BUG] : Incorrect time index propagation in v2 datamodule output #2263

Description

@Chetansahney

Describe the bug

In TslibDataModule v2 dataset output, history_time_idx / future_time_idx could be generated from synthetic sequential values (torch.arange(...)) instead of the real per-series timestep values.

This causes incorrect temporal representation for:
-non-zero-start timelines
-irregular/gapped timelines
-As a result, models may receive distorted time context.

To Reproduce

[
import pandas as pd
import torch
from pytorch_forecasting.data import TimeSeries
from pytorch_forecasting.data._tslib_data_module import TslibDataModule

#irregular, non-zero-start time index
df = pd.DataFrame(
{
"time_idx": [10, 20, 35, 50, 80, 120],
"group_id": ["A"] * 6,
"value": [1.0, 1.2, 1.4, 1.3, 1.5, 1.7],
}
)

ts = TimeSeries(
data=df,
time="time_idx",
target="value",
group=["group_id"],
num=["value"],
known=["time_idx"],
)

dm = TslibDataModule(
time_series_dataset=ts,
context_length=3,
prediction_length=2,
batch_size=1,
train_val_test_split=(1.0, 0.0, 0.0),
)

dm.setup(stage="fit")
batch = next(iter(dm.train_dataloader()))[0]

print(batch["history_time_idx"][0]) # should reflect original values
print(batch["future_time_idx"][0]) # should reflect original values
]

Expected behavior

history_time_idx and future_time_idx should always propagate the original values from processed_data["timestep"] (real dataset time axis), not synthetic positional indices.

Additional context

There is a pre-existing unrelated baseline failure in full test_tslib_data_module.py (test_multivariate_target, list-vs-shape assertion), observed before this fix.

Versions

pytorch-forecasting: current repository state (local clone)
Python / torch / lightning: same as active CI/test environment for validation runs

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Needs triage & validation

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions