question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Easier inheritance of TimeSeries object

See original GitHub issue

I was looking to extend TimeSeries object to make it easier to convert it to other not yet implemented and internal formats. Usually, I’d do something like

from darts import TimeSeries as DartsTimeSeries

class TimeSeries(DartsTimeSeries):
    def to_my_custom_format(self):
        pass

The problem with this approach is that all factory methods in TimeSeries are static and are not aware of the underlying class, which means that

from my_module import TimeSeries
TimeSeries.from_dataframe(df, "time", "value")   # -> darts.timeseries.TimeSeries

still returns darts.timeseries.TimeSeries object without to_my_custom_format() method. Is there a reason why factory methods are implemented as @staticmethod and not @classmethod? The latter would be more friendly from inheritance point of view.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
hrzncommented, Nov 9, 2021

I think there is still another case for making inheritance easier that is (AFAIK) not yet solved by #536.

In some methods of the TimeSeries class, instantiation is done by explicitly calling TimeSeries. Some examples of methods where this is done: head, tail, but also abs etc. I illustrate how this impedes easier inheritance below:

import pandas as pd
from darts.timeseries import TimeSeries # from feature/classmethods branch

class Child(TimeSeries):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        
df = pd.DataFrame({'time':pd.date_range('20210101', periods=10), 'value': range(10)})
ts = Child.from_dataframe(df, time_col='time')
print(type(ts), type(ts.head()))

The above code will result in: <class ‘main.Child’> <class ‘main.TimeSeries’>

If one would change the current TimeSeries call in the head method to self.__class__ the result then becomes: <class ‘main.Child’> <class ‘main.Child’>

Thus retaining any methods defined in Child.

Good catch. We’ll also address these cases, thanks for reporting.

1reaction
hrzncommented, Nov 4, 2021

Yes, this is a good point. There’s no good reason and we’ll make them classmethods.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problems with PostgreSQL 10 for time-series data - Timescale
With its shallow inheritance tree, TimescaleDB avoids these issues, processing fewer tables and allowing easy repartitioning regardless of the ...
Read more >
Speed up time series data ingestion by partitioning tables on ...
In this post, we focus on data ingestion and why partitioned tables help with data ingestion. PostgreSQL has had the ability to handle...
Read more >
TimescaleDB vs. Postgres for time-series: 20x higher inserts ...
It looks like PostgreSQL to the outside world (in fact, it's packaged as an extension), which means it inherits the rock-solid reliability, tooling,...
Read more >
PostgreSQL Time-Series Data Case: Automatic Compression ...
In this article, we'll discuss a case of PostgreSQL time-series data by generating year-on-year and period-over-period comparisons.
Read more >
When you think `class(.) == *`, think again! - The R Blog
Note that matrix objects are not array s in that (inheritance) sense, ... multivariate time series ( "mts" ) extending (simple) time series...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found