Skip to content

Commit 3adcfd2

Browse files
reject wide-mode with different types
1 parent 2eaea98 commit 3adcfd2

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,14 @@ def build_dataframe(args, constructor):
13291329
else:
13301330
wide_cross_name = args["wide_cross"]
13311331
del args["wide_cross"]
1332+
dtype = None
1333+
for v in wide_value_vars:
1334+
if dtype is None:
1335+
dtype = df_output[v].dtype
1336+
elif dtype != df_output[v].dtype:
1337+
raise ValueError(
1338+
"Plotly Express cannot process wide-form data with columns of different type."
1339+
)
13321340
df_output = df_output.melt(
13331341
id_vars=wide_id_vars,
13341342
value_vars=wide_value_vars,

packages/python/plotly/plotly/tests/test_core/test_px/test_px_wide.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,3 +710,13 @@ def test_multi_index():
710710
with pytest.raises(TypeError) as err_msg:
711711
px.scatter(df)
712712
assert "pandas MultiIndex is not supported by plotly express" in str(err_msg.value)
713+
714+
715+
@pytest.mark.parametrize("df", [px.data.stocks(), dict(a=[1, 2], b=["1", "2"])])
716+
def test_mixed_input_error(df):
717+
with pytest.raises(ValueError) as err_msg:
718+
px.line(df)
719+
assert (
720+
"Plotly Express cannot process wide-form data with columns of different type"
721+
in str(err_msg.value)
722+
)

0 commit comments

Comments
 (0)