diff --git a/CHANGELOG.md b/CHANGELOG.md index bdb01caf1a..6768efed3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Updated - Updated Plotly.js from version 2.24.1 to version 2.24.2. See the [plotly.js CHANGELOG](https://github.com/plotly/plotly.js/blob/master/CHANGELOG.md#2242----2023-06-09) for more information. These changes are reflected in the auto-generated `plotly.graph_objects` module. - `px` methods now accept data-frame-like objects that support a [dataframe interchange protocol](https://data-apis.org/dataframe-protocol/latest/index.html), such as polars, vaex, modin etc. This protocol has priority on `to_pandas` call, but will only be used if pandas>=2.0.2 is installed in the environment. +- `px` methods now accept data-frame-like objects that support a `toPandas()` method, such as Spark DataFrames, or a `to_pandas_df()` method, such as Vaex DataFrames. ## [5.15.0] - 2023-06-08 diff --git a/packages/python/plotly/plotly/express/_core.py b/packages/python/plotly/plotly/express/_core.py index 24135fa293..b889bec88d 100644 --- a/packages/python/plotly/plotly/express/_core.py +++ b/packages/python/plotly/plotly/express/_core.py @@ -1331,6 +1331,12 @@ def build_dataframe(args, constructor): elif hasattr(args["data_frame"], "to_pandas"): args["data_frame"] = args["data_frame"].to_pandas() columns = args["data_frame"].columns + elif hasattr(args["data_frame"], "toPandas"): + args["data_frame"] = args["data_frame"].toPandas() + columns = args["data_frame"].columns + elif hasattr(args["data_frame"], "to_pandas_df"): + args["data_frame"] = args["data_frame"].to_pandas_df() + columns = args["data_frame"].columns else: args["data_frame"] = pd.DataFrame(args["data_frame"]) columns = args["data_frame"].columns @@ -1425,9 +1431,14 @@ def build_dataframe(args, constructor): # def __dataframe__(self, ...): # if not some_condition: # self.to_pandas(...) - if not hasattr(df_not_pandas, "to_pandas"): + if hasattr(df_not_pandas, "toPandas"): + args["data_frame"] = df_not_pandas.toPandas() + elif hasattr(df_not_pandas, "to_pandas_df"): + args["data_frame"] = df_not_pandas.to_pandas_df() + elif hasattr(df_not_pandas, "to_pandas"): + args["data_frame"] = df_not_pandas.to_pandas() + else: raise exc - args["data_frame"] = df_not_pandas.to_pandas() df_input = args["data_frame"]