Skip to content

Add linear and zero-fill interpolation strategies to TimeSeriesDataSe…#2227

Open
sujanyd wants to merge 3 commits intosktime:mainfrom
sujanyd:feature/interpolation-strategies
Open

Add linear and zero-fill interpolation strategies to TimeSeriesDataSe…#2227
sujanyd wants to merge 3 commits intosktime:mainfrom
sujanyd:feature/interpolation-strategies

Conversation

@sujanyd
Copy link
Copy Markdown

@sujanyd sujanyd commented Mar 23, 2026

[ENH] Addition of other filling strategies for missing timesteps in TimeSeriesDataSet (GH-1409)
Reference Issues/PRs
Fixes #1409
What does this implement/fix? Explain your changes.
Added support for multiple filling strategies for missing timesteps in TimeSeriesDataSet when allow_missing_timesteps=True.
Previously, only forward fill was supported. This PR adds:

"forward_fill" — repeats the last known value (default, backward compatible)
"linear" — linearly interpolates between boundary values for real-valued variables, falls back to forward fill for categorical variables
"zero" — fills missing values with 0.0
Dict support — per-variable strategy e.g. {"value": "linear", "cat": "forward_fill"}

Changes made:

Modified _timeseries.py — added interpolation_strategy parameter to init and interpolation logic to getitem
Added docstring for the new parameter
Added test file tests/test_data/test_interpolation.py
Added demo script for visual verification of all strategies

What should a reviewer concentrate their feedback on?

The interpolation logic inside getitem — specifically how gaps are detected and filled
Whether the fallback to forward fill for categorical variables when "linear" is specified is the right behavior
Edge case handling — gaps at sequence boundaries, multiple consecutive gaps
Backward compatibility — default behavior should be identical to before this change

Did you add any tests for the change?
Yes. Added tests/test_data/test_interpolation.py which covers:

Forward fill (default behavior preserved)
Linear interpolation across a gap
Zero fill
Mixed per-variable strategy using a dictionary

Any other comments?

A demo script is included to visually compare all three strategies on a sample dataset with a gap
Linear interpolation is only applied to real-valued variables — categorical variables always fall back to forward fill regardless of strategy specified
This is a purely additive change — no existing behavior is modified

PR checklist

The PR title starts with [ENH]
Added/modified tests
Used pre-commit hooks when committing to ensure that code is compliant with hooks. Install hooks with pre-commit install.
To run hooks independent of commit, execute pre-commit run --all-files

@review-notebook-app
Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@602ee15). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2227   +/-   ##
=======================================
  Coverage        ?   86.76%           
=======================================
  Files           ?      166           
  Lines           ?     9781           
  Branches        ?        0           
=======================================
  Hits            ?     8486           
  Misses          ?     1295           
  Partials        ?        0           
Flag Coverage Δ
cpu 86.76% <100.00%> (?)
pytest 86.76% <100.00%> (?)

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.

@sujanyd sujanyd marked this pull request as ready for review March 23, 2026 17:12
@sujanyd sujanyd marked this pull request as draft March 23, 2026 17:22
@sujanyd sujanyd marked this pull request as ready for review March 24, 2026 04:46
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.

Addition of other filling strategies for missing timesteps in TimeSeriesDataset

1 participant