Skip to content

Commit 5f87ec4

Browse files
Merge pull request #2598 from plotly/loosen_wide_typecheck
accept integer and float columns in wide mode
2 parents e281bc9 + c9742e0 commit 5f87ec4

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
99
- Fixed special cases with `px.sunburst` and `px.treemap` with `path` input ([#2524](https://github.com/plotly/plotly.py/pull/2524))
1010
- Fixed bug in `hover_data` argument of `px` functions, when the column name is changed with labels and `hover_data` is a dictionary setting up a specific format for the hover data ([#2544](https://github.com/plotly/plotly.py/pull/2544)).
1111
- Made the Plotly Express `trendline` argument more robust and made it work with datetime `x` values ([#2554](https://github.com/plotly/plotly.py/pull/2554))
12+
- Plotly Express wide mode now accepts mixed integer and float columns ([#2598](https://github.com/plotly/plotly.py/pull/2598))
1213

1314
## [4.8.1] - 2020-05-28
1415

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -1390,9 +1390,11 @@ def build_dataframe(args, constructor):
13901390
del args["wide_cross"]
13911391
dtype = None
13921392
for v in wide_value_vars:
1393+
v_dtype = df_output[v].dtype.kind
1394+
v_dtype = "number" if v_dtype in ["i", "f", "u"] else v_dtype
13931395
if dtype is None:
1394-
dtype = df_output[v].dtype
1395-
elif dtype != df_output[v].dtype:
1396+
dtype = v_dtype
1397+
elif dtype != v_dtype:
13961398
raise ValueError(
13971399
"Plotly Express cannot process wide-form data with columns of different type."
13981400
)

Diff for: packages/python/plotly/plotly/tests/test_core/test_px/test_px_wide.py

+6
Original file line numberDiff line numberDiff line change
@@ -742,3 +742,9 @@ def test_mixed_input_error(df):
742742
"Plotly Express cannot process wide-form data with columns of different type"
743743
in str(err_msg.value)
744744
)
745+
746+
747+
def test_mixed_number_input():
748+
df = pd.DataFrame(dict(a=[1, 2], b=[1.1, 2.1]))
749+
fig = px.line(df)
750+
assert len(fig.data) == 2

0 commit comments

Comments
 (0)