From b6fce1808affe1b329a14c7c5a9241abb733105d Mon Sep 17 00:00:00 2001 From: Liam Connors Date: Thu, 27 Jul 2023 16:11:24 -0400 Subject: [PATCH 1/7] Update _core.py --- packages/python/plotly/plotly/express/_core.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/python/plotly/plotly/express/_core.py b/packages/python/plotly/plotly/express/_core.py index 24135fa293..2b320caeaf 100644 --- a/packages/python/plotly/plotly/express/_core.py +++ b/packages/python/plotly/plotly/express/_core.py @@ -1331,6 +1331,9 @@ 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 else: args["data_frame"] = pd.DataFrame(args["data_frame"]) columns = args["data_frame"].columns @@ -1425,9 +1428,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 not hasattr(df_not_pandas, "to_pandas") or hasattr( + df_not_pandas, "toPandas" + ): raise exc - args["data_frame"] = df_not_pandas.to_pandas() + if hasattr(df_not_pandas, "toPandas"): + args["data_frame"] = df_not_pandas.toPandas() + else: + args["data_frame"] = df_not_pandas.to_pandas() df_input = args["data_frame"] From baf95693cfd58b138d05b9c9f045eff3a570d492 Mon Sep 17 00:00:00 2001 From: Liam Connors Date: Thu, 27 Jul 2023 16:11:30 -0400 Subject: [PATCH 2/7] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bdb01caf1a..db7c0c7253 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. ## [5.15.0] - 2023-06-08 From 62d864b35a0e05af978a535bb54f09e394464990 Mon Sep 17 00:00:00 2001 From: Liam Connors Date: Fri, 28 Jul 2023 10:23:37 -0400 Subject: [PATCH 3/7] Update CHANGELOG.md Co-authored-by: Alex Johnson --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db7c0c7253..9ea0abf23a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +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. +- `px` methods now accept data-frame-like objects that support a `toPandas()` method, such as Spark DataFrames. ## [5.15.0] - 2023-06-08 From 9978e3e9911a6b185eb9ea51b1a593f73f98e996 Mon Sep 17 00:00:00 2001 From: Liam Connors Date: Fri, 28 Jul 2023 14:31:17 -0400 Subject: [PATCH 4/7] fix check for to_pandas and toPandas --- packages/python/plotly/plotly/express/_core.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/python/plotly/plotly/express/_core.py b/packages/python/plotly/plotly/express/_core.py index 2b320caeaf..0ef6d55334 100644 --- a/packages/python/plotly/plotly/express/_core.py +++ b/packages/python/plotly/plotly/express/_core.py @@ -1428,8 +1428,9 @@ def build_dataframe(args, constructor): # def __dataframe__(self, ...): # if not some_condition: # self.to_pandas(...) - if not hasattr(df_not_pandas, "to_pandas") or hasattr( - df_not_pandas, "toPandas" + if not ( + hasattr(df_not_pandas, "to_pandas") + or hasattr(df_not_pandas, "toPandas") ): raise exc if hasattr(df_not_pandas, "toPandas"): From d5a753185ceb45c2f97ee836bddfffd0742d39a5 Mon Sep 17 00:00:00 2001 From: Liam Connors Date: Mon, 31 Jul 2023 18:45:42 -0400 Subject: [PATCH 5/7] add support for to_pandas_df --- packages/python/plotly/plotly/express/_core.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/python/plotly/plotly/express/_core.py b/packages/python/plotly/plotly/express/_core.py index 0ef6d55334..116dd61d3c 100644 --- a/packages/python/plotly/plotly/express/_core.py +++ b/packages/python/plotly/plotly/express/_core.py @@ -1334,6 +1334,9 @@ def build_dataframe(args, constructor): 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 @@ -1431,10 +1434,13 @@ def build_dataframe(args, constructor): if not ( hasattr(df_not_pandas, "to_pandas") or hasattr(df_not_pandas, "toPandas") + or hasattr(df_not_pandas, "to_pandas_df") ): raise exc 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() else: args["data_frame"] = df_not_pandas.to_pandas() From 9b032019bba23c76b602f50685ec2a32457ae936 Mon Sep 17 00:00:00 2001 From: Liam Connors Date: Tue, 1 Aug 2023 10:13:48 -0400 Subject: [PATCH 6/7] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ea0abf23a..6768efed3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +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. +- `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 From 2a409f1e234b6ee6352bfd10a6469a4609250bfc Mon Sep 17 00:00:00 2001 From: Liam Connors Date: Tue, 1 Aug 2023 21:14:18 -0400 Subject: [PATCH 7/7] Update _core.py --- packages/python/plotly/plotly/express/_core.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/packages/python/plotly/plotly/express/_core.py b/packages/python/plotly/plotly/express/_core.py index 116dd61d3c..b889bec88d 100644 --- a/packages/python/plotly/plotly/express/_core.py +++ b/packages/python/plotly/plotly/express/_core.py @@ -1431,18 +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") - or hasattr(df_not_pandas, "toPandas") - or hasattr(df_not_pandas, "to_pandas_df") - ): - raise exc 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() - else: + elif hasattr(df_not_pandas, "to_pandas"): args["data_frame"] = df_not_pandas.to_pandas() + else: + raise exc df_input = args["data_frame"]