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

Add TimeSeries.from_polars #2635

Open
baggiponte opened this issue Jan 2, 2025 · 3 comments
Open

Add TimeSeries.from_polars #2635

baggiponte opened this issue Jan 2, 2025 · 3 comments
Labels
feature request Use this label to request a new feature

Comments

@baggiponte
Copy link

baggiponte commented Jan 2, 2025

Is your feature request related to a current problem? Please describe.
I was trying to use darts with Polars, but casting a Polars DataFrame into a TimeSeries hardly works.

Describe proposed solution
There are two ways of doing this:

  1. quick and dirty: add a TimeSeries.from_polars classmethod that handles conversion with mostly custom logic (this could potentially entail deprecating from_dataframe and renaming it into from_pandas: it's not the de facto dataframe library anymore).
  2. Use narwhals to rewrite TimeSeries.from_dataframe and support all dataframe backends that narwhals does.

To give a bit of context: narwhals is a new project that's grown a lot this year. It's a very thin, zero-dependency library for developers to write dataframe-agnostic code. It's quite used: plotly 6.0 will use polars for (AFAIK) all its dataframe manipulation, and so do already libraries like altair, marimo, hierarchicalforecast by nixtla...

Glad to provide more details 😊

@baggiponte baggiponte added the triage Issue waiting for triaging label Jan 2, 2025
@madtoinou
Copy link
Collaborator

Hi @baggiponte,

I really like the idea of re-implementing from_dataframe using narwahls so that darts can support both pandas and polars, it should not be too difficult... Let's see what @dennisbader thinks about it!

If this feature request makes it to the roadmap, would you have the time to contribute and open a PR for it?

@baggiponte
Copy link
Author

Ciao @madtoinou, thanks for the prompt reply! I would love to, but not sure if I have time this month. However, I am sure that @FBruzzesi and @MarcoGorelli might help (me) out - they are usually always available for narwhalification 🦄

On the implementation detail side, I guess the signature of the function could and should stay the same, am I right?

@dennisbader
Copy link
Collaborator

Thanks for this feature request @baggiponte. I like the idea of adding support for polars (and others) to our factory methods.

I quickly checked out narwhals and it definitely looks interesting.

Just to clarify that we're all on the same page: We only want to add support for converting polars, ... DataFrames into TimeSeries (meaning xarray). So the TimeSeries itself will not run e.g. on polars for downstream tasks.

Solution 2. seems like a nice solution for me if we can guarantee that the performance doesn't suffer for the pandas support.

If we do that, then we could also add support for other methods:

  • from_series()
  • from_group_dataframe()

What do you think?

@dennisbader dennisbader added feature request Use this label to request a new feature and removed triage Issue waiting for triaging labels Jan 5, 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
None yet
Development

No branches or pull requests

3 participants