Skip to content

Commit f727bfa

Browse files
use pandas 1.5.0 to consume other dataframes
1 parent a09f858 commit f727bfa

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

Diff for: packages/python/plotly/plotly/express/_core.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -1304,14 +1304,17 @@ def build_dataframe(args, constructor):
13041304
df_provided = args["data_frame"] is not None
13051305
if df_provided and not isinstance(args["data_frame"], pd.DataFrame):
13061306
if hasattr(args["data_frame"], "__dataframe__"):
1307-
# Pandas does not implement a `from_dataframe` yet
1308-
# $ wget https://raw.githubusercontent.com/data-apis/dataframe-api/main/protocol/pandas_implementation.py
1309-
# $ export PYTHONPATH=`pwd`
1310-
import pandas_implementation
1311-
1312-
args["data_frame"] = pandas_implementation.from_dataframe(
1313-
args["data_frame"]
1314-
)
1307+
try:
1308+
import pandas.api.interchange
1309+
except ModuleNotFoundError:
1310+
raise NotImplementedError(
1311+
"The dataframe you provided supports the dataframe interchange"
1312+
"protocol, "
1313+
"but pandas 1.5.0 or greater is required to consume it."
1314+
)
1315+
df_not_pandas = args["data_frame"]
1316+
df_pandas = pandas.api.interchange.from_dataframe(df_not_pandas)
1317+
args["data_frame"] = df_pandas
13151318
else:
13161319
args["data_frame"] = pd.DataFrame(args["data_frame"])
13171320
df_input = args["data_frame"]

Diff for: packages/python/plotly/plotly/tests/test_optional/test_px/test_px_input.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def test_build_df_with_index():
236236
def test_build_df_protocol():
237237
import vaex
238238

239-
# take out the 'species' columns since the vaex implementation does not cover strings yet
239+
# take out the 'species' columns since there are still some issues with strings
240240
iris_pandas = px.data.iris()[["petal_width", "sepal_length"]]
241241
iris_vaex = vaex.from_pandas(iris_pandas)
242242
args = dict(data_frame=iris_vaex, x="petal_width", y="sepal_length")

0 commit comments

Comments
 (0)