Skip to content

Commit b75324b

Browse files
maartenbreddelsanmyachev
authored andcommitted
use pandas 1.5.0 to consume other dataframes
1 parent 3c2d1bf commit b75324b

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

packages/python/plotly/plotly/express/_core.py

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

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)