Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Union function to find the intersection of time series #2042

Open
Tristanjmeyers opened this issue Oct 31, 2023 · 1 comment · May be fixed by #2592
Open

Union function to find the intersection of time series #2042

Tristanjmeyers opened this issue Oct 31, 2023 · 1 comment · May be fixed by #2592
Assignees
Labels
feature request Use this label to request a new feature good first issue Good for newcomers

Comments

@Tristanjmeyers
Copy link

Hello!
I think it would be incredibly valuable to have a function that finds the intersection of a list of time series. This would be something akin to xarray's "align" function, which finds the intersection across a list of variables.

I commonly find I have to manually convert my TimeSerries back to an xarray data array, run an align, then convert back to a TimeSeries. For instance:

import xarray as xr
from darts.timeseries import TimeSeries

ts1 = TimeSeries.from_csv('file1.csv', time_col='time')
ts2 = TimeSeries.from_csv('file2.csv', time_col='time')
ts3 = TimeSeries.from_csv('file3.csv', time_col='time')


ts1_, ts2_, ts3_ = xr.align( ts1.data_array(), ts2.data_array(), ts3.data_array(), exclude = 'component')

ts1 =  TimeSeries(ts1_)
ts2 =  TimeSeries(ts2_)
ts3 =  TimeSeries(ts3_)

So something like:

ts1 = TimeSeries.from_csv('file1.csv', time_col='time')
ts2 = TimeSeries.from_csv('file2.csv', time_col='time')
ts3 = TimeSeries.from_csv('file3.csv', time_col='time')

ts1, ts2, ts3 = Timeseries.intersection(ts1, ts2, ts3)

if the intersection doesn't exist, it could raise a warning like: Warning: there is no overlapping times between the time series.

Another option would also be an option for "stack" to take an argument to do this intersection:

full_ts = ts1.stack(ts2, intersection = True).stack(ts3, intersection = True)

And finally, if this could be added in the pipeline API, that would be excellent!

Apologies if these features already exists! I am new to the package, but I couldn't find an example or something like this in the API. I am loving it so far though!

@Tristanjmeyers Tristanjmeyers added the triage Issue waiting for triaging label Oct 31, 2023
@madtoinou
Copy link
Collaborator

Hi @Tristanjmeyers,

This features is already implemented in TimeSeries.slice_intersect() (doc), you'll have to call it several times if you have more than two series.

I like the idea of offering this feature as a data-transformer so that it can be included in a Pipeline, WDYT @dennisbader ?

@madtoinou madtoinou added feature request Use this label to request a new feature good first issue Good for newcomers and removed triage Issue waiting for triaging labels Oct 31, 2023
@dennisbader dennisbader added this to darts Nov 5, 2024
@github-project-automation github-project-automation bot moved this to To do in darts Nov 5, 2024
@dennisbader dennisbader moved this from To do to In review in darts Nov 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Use this label to request a new feature good first issue Good for newcomers
Projects
Status: In review
3 participants