Skip to content

[ENH] Add TimeSeries datatype as per new API - #2410

Open
phoeenniixx wants to merge 10 commits into
sktime:v2-devfrom
phoeenniixx:ts
Open

phoeenniixx wants to merge 10 commits into
sktime:v2-devfrom
phoeenniixx:ts

Conversation

@phoeenniixx

@phoeenniixx phoeenniixx commented Sep 6, 2026 •

Copy link
Copy Markdown
Member

This PR adds the new Add TimeSeries datatype and update datamodule with the new design.
See #2407, #2398

  • TimeSeries is now a standarised datatype. Updated the tests and renamed the file to test_timeseries_v2 as this is no more a D1 layer!

  • Also, we now have metadata as a dataclass, instead of the dict to make it more user friendly.
    Updated tests also updates some old ones (and removes some tests like init checks - which are not needed i think?)

This PR is aimed at v2-dev instead of main, so that we dont break current user code until this design is complete and stable. See #2407 for details. So I had to update the branch target in the workflows for the tests to run (which might fail due to the changes)

Stack

Note

The tutorials will fail for sure, will update the notebook in one of the branchs stacked over this PR.
Still need to add the Forecaster and tests - will add the notebook and docs changes on the upcoming branches as the vignette is incomplete without forecaster which is not in this PR.

Changes made

  • Changed the test file of TimeSeries from test_d1 tro test_timeseries_v2
  • updates to TimeSeries
    • Now uses TimeSeriesMetadata as metadata inplace of a dict
    • Not a Dataset anymore
    • Added some auto-detection of cols
      • target is the last column of data.
      • time is the first column not already used as group, target, static or weight. If no such column exists, ValueError is raised - pass time explicitly.
      • num and cat are the dtype split over all columns that are not group, time or weight
    • data validation
    • to_pandas to create a df
    • from_tensors to create a TimeSeries class for predicitons
      • which lack a lot of metadata, so need special handling otherwise will interfere with the input data validation

@phoeenniixx phoeenniixx self-assigned this Sep 6, 2026
@phoeenniixx phoeenniixx added enhancement New feature or request API design API design & software architecture module:datasets&dataloaders ptf-v2 Related to `pytorch-forecasting` v2 labels Sep 6, 2026
@phoeenniixx

Copy link
Copy Markdown
Member Author

Will stack a PR for Forecaster over this PR

@codecov

codecov Bot commented Sep 6, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 56.83453% with 60 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (v2-dev@67c354f). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...orch_forecasting/data/timeseries/_timeseries_v2.py 50.00% 40 Missing ⚠️
pytorch_forecasting/utils/_validation.py 50.00% 17 Missing ⚠️
pytorch_forecasting/data/_metadata.py 87.50% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             v2-dev    #2410   +/-   ##
=========================================
  Coverage          ?   87.79%           
=========================================
  Files             ?      202           
  Lines             ?    11292           
  Branches          ?        0           
=========================================
  Hits              ?     9914           
  Misses            ?     1378           
  Partials          ?        0           
Flag Coverage Δ
cpu 87.79% <56.83%> (?)
pytest 87.79% <56.83%> (?)

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

☔ View full report in Codecov by Harness.
📢 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.


self.save_hyperparameters(ignore=["loss", "logging_metrics", "optimizer"])
self.save_hyperparameters(
ignore=["loss", "logging_metrics", "optimizer", "metadata"]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to add metadata (which is a dataclass now) to ignore as otherwise it causes issue of UnpicklingError of torch.

@phoeenniixx

Copy link
Copy Markdown
Member Author

After talking to @CloseChoice, i will try to break this PR into smaller chunks and try to incorporate @Faakhir30's #2313 in here as well to create a Base data module

@phoeenniixx phoeenniixx changed the title [ENH] Add TimeSeries datatype and update datamodule with the new design [ENH] Add TimeSeries datatype as per new API Sep 11, 2026
@phoeenniixx

Copy link
Copy Markdown
Member Author

After discussion with @fkiraly, I understood the issue in my mental model - Although Dataset alone doesnt provide any "functionality" to us, but it does provide a "contract" that the user will expect from a torch workflow - that a data container (TimeSeries) is a common torch data container (or Dataset). This is important that we keep the contract same to prevent any confusion.

So, in the recent commit, TimeSeries is made a Dataset class instead.

-------
t : numpy.ndarray of shape (n_timepoints,)
Time index for each time point in the past or present. Aligned with `y`,
and `x` not ending in `f`.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to make this docstring better and clearer - also check other docstrings which might not be clear enough

@CloseChoice CloseChoice left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just some minor comments.

self.metadata = {
"cols": {
all_cols = self._target + self.feature_cols + self._static
self.metadata = TimeSeriesMetadata(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this makes the PR breaking, are breaking changes somewhere documented e.g. in a migration guide?

)


def _check_positive(value, name, allow_none=False):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this name is slightly confusing since positive usually means >0, if only ints are handed over it's fine but I don't see type hints here though in the params it is stated that it is int only.

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

Labels

API design API design & software architecture enhancement New feature or request module:datasets&dataloaders ptf-v2 Related to `pytorch-forecasting` v2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants