diff --git a/CHANGELOG.md b/CHANGELOG.md index f6e9fdc3702..d5f8420a94b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/packages/python/plotly/plotly/express/_core.py b/packages/python/plotly/plotly/express/_core.py index d89794a5a49..35b0b9840d7 100644 --- a/packages/python/plotly/plotly/express/_core.py +++ b/packages/python/plotly/plotly/express/_core.py @@ -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." ) diff --git a/packages/python/plotly/plotly/tests/test_core/test_px/test_px_wide.py b/packages/python/plotly/plotly/tests/test_core/test_px/test_px_wide.py index 2c49b4bb63b..87aff6fac2f 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_px/test_px_wide.py +++ b/packages/python/plotly/plotly/tests/test_core/test_px/test_px_wide.py @@ -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