From 8b58c7f175301a8ee615b51c239237292441a52a Mon Sep 17 00:00:00 2001 From: Nicolas Kruchten Date: Sun, 25 Sep 2022 07:34:30 -0400 Subject: [PATCH] PX can accept non-pandas dataframes that can .to_pandas() --- CHANGELOG.md | 7 +++++++ packages/python/plotly/plotly/express/_core.py | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16bddfdc5bb..cd60c4b4d02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). + +## UNRELEASED + +### Updated + - `px` methods now accept data-frame-like objects that support a `to_pandas()` method, such as polars, cudf, vaex etc + + ## [5.10.0] - 2022-08-11 ### Updated diff --git a/packages/python/plotly/plotly/express/_core.py b/packages/python/plotly/plotly/express/_core.py index dd2d53be1ed..c4b4cc85684 100644 --- a/packages/python/plotly/plotly/express/_core.py +++ b/packages/python/plotly/plotly/express/_core.py @@ -1303,7 +1303,10 @@ def build_dataframe(args, constructor): # Cast data_frame argument to DataFrame (it could be a numpy array, dict etc.) df_provided = args["data_frame"] is not None if df_provided and not isinstance(args["data_frame"], pd.DataFrame): - args["data_frame"] = pd.DataFrame(args["data_frame"]) + if hasattr(args["data_frame"], "to_pandas"): + args["data_frame"] = args["data_frame"].to_pandas() + else: + args["data_frame"] = pd.DataFrame(args["data_frame"]) df_input = args["data_frame"] # now we handle special cases like wide-mode or x-xor-y specification