plotly / plotly.py

The interactive graphing library for Python :sparkles: This project now includes Plotly Express!
https://plotly.com/python/
MIT License
16.34k stars 2.56k forks source link

Explore dropping Pandas requirement for Plotly Express #4834

Open ndrezn opened 1 month ago

ndrezn commented 1 month ago

In https://github.com/plotly/plotly.py/pull/4790, nearly all Pandas functionality is removed from Plotly.py, except some of our trendine functions.

Narwhals does not yet support rolling, expanding nor ewm, and until that support is added, we need to use Pandas to calculate trendlines.

Those functions are on the Narwhals roadmap, and we should have a quick follow-up in Plotly.py to implement those changes after the first set of Narwhals changes are made and the good folks at Narwhals release that update 🙂 .

See: https://github.com/plotly/plotly.py/pull/4790/files/6676061152527160b44dbf67ecf6b89e46eef3b2#diff-e667a84629ee8d2879cf22a88c8ff80bcfec1c35be69ab9f50be5938c7089ddaR114-R129

FBruzzesi commented 3 weeks ago

Commenting here to brainstorm how to eventually achieve this.

Currently it is possible to pass trendline_options to forward kwargs to the underlying (pandas) trendline function.

If we were to implement rolling and ewm in narwhals, they would have (a subset of) the polars respective method signature. This would result in a breaking change in plotly, as the pandas kwargs are different.

I think the most reasonable option would be to remap pandas arguments to narwhals with a deprecation warning for a first period, and eventually remove support for pandas specific.

Thoughts on it?

cc: @MarcoGorelli

FBruzzesi commented 1 week ago

Tiny update on this topic: after merging all the cumulative features supported from polars into the narwhals api, I am able to replicate almost all the univariate expanding functions that pandas supports. The following 3 are sadly left out: median, quantile, and rank. I don't really see a way to implement them without a loop for polars and pyarrow considering their api's.