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

Extend TimeSeries.resample() to be more like pandas resample() #699

Closed
vfilter opened this issue Dec 19, 2021 · 3 comments · Fixed by #2654
Closed

Extend TimeSeries.resample() to be more like pandas resample() #699

vfilter opened this issue Dec 19, 2021 · 3 comments · Fixed by #2654
Assignees
Labels
feature request Use this label to request a new feature

Comments

@vfilter
Copy link

vfilter commented Dec 19, 2021

Describe the bug
Hi, I'm trying to downsample a high-frequency Darts time series object to daily/monthly/yearly mean/sum/min/max etc. But the behavior is different than Pandas, so my only current option is to downsample before converting to a time series object.

To Reproduce

import pandas as pd
import numpy as np
from darts import TimeSeries
from darts.datasets import MonthlyMilkDataset, MonthlyMilkIncompleteDataset

series = MonthlyMilkDataset().load()

series.resample('Y').sum()

Results in

component Pounds per cow 10094.0 dtype: float64

Expected behavior
Expected a time series with the sum of each year, rather than the sum of all years. That is the default behaviour of the pandas resample method and I'm having a hard time understanding why this wouldn't work in Darts.

System (please complete the following information):

  • Python version: 3.9
  • darts version: 0.14.0
@vfilter vfilter added bug Something isn't working triage Issue waiting for triaging labels Dec 19, 2021
@dennisbader
Copy link
Collaborator

Hi @vfilter and thanks for writing. Our resample() method works different to pandas resample.
From our docs:

Resample creates a reindexed time series with a given frequency.
The method is used to fill holes in reindexed TimeSeries, by default 'pad'.

It is true that it would be nice to extend our method to be more like pandas` resample. I will add this to our backlog.

You can achieve the desired results with:

TimeSeries.from_dataframe(series.pd_dataframe().resample('Y').sum())

@dennisbader dennisbader added feature request Use this label to request a new feature and removed bug Something isn't working labels Dec 20, 2021
@dennisbader dennisbader changed the title [BUG] Resample with specific method doesn't work as expected Extend TimeSeries.resample() to be more like pandas resample() Dec 20, 2021
@dennisbader
Copy link
Collaborator

Pandas returns a *IndexResampler. We could either extend resample() or implement a new method. We could add support for IndexResampler to our stats methods like sum() which would convert it back into a TimeSeries object.

@ahgraber
Copy link

ahgraber commented Feb 3, 2023

Following this issue with interest! Aggregate resample is critical to many of our workflows. Currently, we're using this function to retain timeseries metadata attributes, but it feels a bit hacky

def ts_resample(ts, freq="Y", agg="sum"):
    tmp = TimeSeries.from_dataframe(ts.pd_dataframe().resample(freq).agg(agg))
    tmp = tmp.with_static_covariates(ts.static_covariates)
    tmp = tmp.with_hierarchy(ts.hierarchy)
    return tmp

@github-project-automation github-project-automation bot moved this to To do in darts Sep 24, 2024
@madtoinou madtoinou moved this from To do to In review in darts Jan 21, 2025
@dennisbader dennisbader mentioned this issue Jan 24, 2025
3 tasks
@github-project-automation github-project-automation bot moved this from In review to Done in darts Jan 24, 2025
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
Projects
Status: Done
4 participants