From 8f01945e0dfecc9d28b1655154027945430228a6 Mon Sep 17 00:00:00 2001 From: Nicolas Kruchten Date: Thu, 25 Jun 2020 08:33:08 -0400 Subject: [PATCH 1/3] accept integer and float columns in wide mode --- CHANGELOG.md | 1 + packages/python/plotly/plotly/express/_core.py | 6 ++++-- .../plotly/plotly/tests/test_core/test_px/test_px_wide.py | 6 ++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f6e9fdc3702..9cb0a05e169 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 () ## [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..b610e267068 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"] 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 From 2f050f2951b52318e4d4170008b693a3654b5161 Mon Sep 17 00:00:00 2001 From: Nicolas Kruchten Date: Thu, 25 Jun 2020 08:34:04 -0400 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9cb0a05e169..d5f8420a94b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +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 () +- 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 From c9742e03565e3956b077ec401dec286e70a18a50 Mon Sep 17 00:00:00 2001 From: Nicolas Kruchten Date: Thu, 25 Jun 2020 09:28:00 -0400 Subject: [PATCH 3/3] Update packages/python/plotly/plotly/express/_core.py Co-authored-by: Emmanuelle Gouillart --- packages/python/plotly/plotly/express/_core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/python/plotly/plotly/express/_core.py b/packages/python/plotly/plotly/express/_core.py index b610e267068..35b0b9840d7 100644 --- a/packages/python/plotly/plotly/express/_core.py +++ b/packages/python/plotly/plotly/express/_core.py @@ -1391,7 +1391,7 @@ def build_dataframe(args, constructor): dtype = None for v in wide_value_vars: v_dtype = df_output[v].dtype.kind - v_dtype = "number" if v_dtype in ["i", "f"] else v_dtype + v_dtype = "number" if v_dtype in ["i", "f", "u"] else v_dtype if dtype is None: dtype = v_dtype elif dtype != v_dtype: