Skip to content

Commit e301999

Browse files
committed
catch exceptions and try another way
Signed-off-by: Anatoly Myachev <[email protected]>
1 parent 5f7bb34 commit e301999

File tree

1 file changed

+11
-1
lines changed
  • packages/python/plotly/plotly/express

1 file changed

+11
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,17 @@ def build_dataframe(args, constructor):
13141314
import pandas.api.interchange
13151315

13161316
df_not_pandas = args["data_frame"]
1317-
df_pandas = pandas.api.interchange.from_dataframe(df_not_pandas)
1317+
try:
1318+
df_pandas = pandas.api.interchange.from_dataframe(df_not_pandas)
1319+
except (ImportError, NotImplementedError) as exc:
1320+
# temporary workaround; developers of third-party libraries themselves
1321+
# should try a different implementation, if available. For example:
1322+
# def __dataframe__(self, ...):
1323+
# if not some_condition:
1324+
# self.to_pandas(...)
1325+
if not hasattr(df_not_pandas, "to_pandas"):
1326+
raise exc
1327+
df_not_pandas.to_pandas()
13181328
args["data_frame"] = df_pandas
13191329
elif hasattr(args["data_frame"], "to_pandas"):
13201330
args["data_frame"] = args["data_frame"].to_pandas()

0 commit comments

Comments
 (0)