Skip to content

Commit

Permalink
Merge pull request #2598 from plotly/loosen_wide_typecheck
Browse files Browse the repository at this point in the history
accept integer and float columns in wide mode
  • Loading branch information
nicolaskruchten authored Jun 25, 2020
2 parents e281bc9 + c9742e0 commit 5f87ec4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Fixed special cases with `px.sunburst` and `px.treemap` with `path` input ([#2524](https://github.com/plotly/plotly.py/pull/2524))
- 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)).
- 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))
- Plotly Express wide mode now accepts mixed integer and float columns ([#2598](https://github.com/plotly/plotly.py/pull/2598))

## [4.8.1] - 2020-05-28

Expand Down
6 changes: 4 additions & 2 deletions packages/python/plotly/plotly/express/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1390,9 +1390,11 @@ def build_dataframe(args, constructor):
del args["wide_cross"]
dtype = None
for v in wide_value_vars:
v_dtype = df_output[v].dtype.kind
v_dtype = "number" if v_dtype in ["i", "f", "u"] else v_dtype
if dtype is None:
dtype = df_output[v].dtype
elif dtype != df_output[v].dtype:
dtype = v_dtype
elif dtype != v_dtype:
raise ValueError(
"Plotly Express cannot process wide-form data with columns of different type."
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -742,3 +742,9 @@ def test_mixed_input_error(df):
"Plotly Express cannot process wide-form data with columns of different type"
in str(err_msg.value)
)


def test_mixed_number_input():
df = pd.DataFrame(dict(a=[1, 2], b=[1.1, 2.1]))
fig = px.line(df)
assert len(fig.data) == 2

0 comments on commit 5f87ec4

Please sign in to comment.