From 052e2c1b9a8b14bc7042d9610cd1d038106bdd05 Mon Sep 17 00:00:00 2001 From: AaronStiff <69512633+AaronStiff@users.noreply.github.com> Date: Wed, 25 Jan 2023 19:33:23 -0400 Subject: [PATCH 1/5] added: ignore facet args with empty dataset --- packages/python/plotly/plotly/express/_core.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/python/plotly/plotly/express/_core.py b/packages/python/plotly/plotly/express/_core.py index 437df83de7d..91d656515b2 100644 --- a/packages/python/plotly/plotly/express/_core.py +++ b/packages/python/plotly/plotly/express/_core.py @@ -1988,6 +1988,10 @@ def make_figure(args, constructor, trace_patch=None, layout_patch=None): layout_patch = layout_patch or {} apply_default_cascade(args) + # Ignore facet rows and columns when data frame is empty so as to prevent nrows/ncols equaling 0 + if len(args["data_frame"]) == 0: + args["facet_row"] = args["facet_col"] = None + args = build_dataframe(args, constructor) if constructor in [go.Treemap, go.Sunburst, go.Icicle] and args["path"] is not None: args = process_dataframe_hierarchy(args) From 7a14376861ec293f636289328788caee5896d22c Mon Sep 17 00:00:00 2001 From: AaronStiff <69512633+AaronStiff@users.noreply.github.com> Date: Sat, 28 Jan 2023 19:38:53 -0400 Subject: [PATCH 2/5] moved changes into infer_config --- packages/python/plotly/plotly/express/_core.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/python/plotly/plotly/express/_core.py b/packages/python/plotly/plotly/express/_core.py index 91d656515b2..c98ca6ec249 100644 --- a/packages/python/plotly/plotly/express/_core.py +++ b/packages/python/plotly/plotly/express/_core.py @@ -1875,6 +1875,10 @@ def infer_config(args, constructor, trace_patch, layout_patch): args[position] = args["marginal"] args[other_position] = None + # Ignore facet rows and columns when data frame is empty so as to prevent nrows/ncols equaling 0 + if len(args["data_frame"]) == 0: + args["facet_row"] = args["facet_col"] = None + # If both marginals and faceting are specified, faceting wins if args.get("facet_col") is not None and args.get("marginal_y") is not None: args["marginal_y"] = None @@ -1988,10 +1992,6 @@ def make_figure(args, constructor, trace_patch=None, layout_patch=None): layout_patch = layout_patch or {} apply_default_cascade(args) - # Ignore facet rows and columns when data frame is empty so as to prevent nrows/ncols equaling 0 - if len(args["data_frame"]) == 0: - args["facet_row"] = args["facet_col"] = None - args = build_dataframe(args, constructor) if constructor in [go.Treemap, go.Sunburst, go.Icicle] and args["path"] is not None: args = process_dataframe_hierarchy(args) From e6dd4b459c5ae9a269fb7c14d5defd8106497c4a Mon Sep 17 00:00:00 2001 From: Aaron Stiff <69512633+AaronStiff@users.noreply.github.com> Date: Tue, 9 May 2023 18:36:32 -0300 Subject: [PATCH 3/5] added test --- test/percy/plotly-express.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/percy/plotly-express.py b/test/percy/plotly-express.py index 85bd910712d..9d61708fbc5 100644 --- a/test/percy/plotly-express.py +++ b/test/percy/plotly-express.py @@ -543,3 +543,11 @@ ) fig = px.timeline(df, x_start="Start", x_end="Finish", y="Task", color="Task") fig.write_html(os.path.join(dir_name, "timeline.html"), auto_play=False) + + +px.bar( + pd.DataFrame(columns=['A', 'B', 'X']), + x = 'A', + y = 'X', + facet_col = 'B' +) From 36823a90fc0308e8448bb85cf58e6b550b065412 Mon Sep 17 00:00:00 2001 From: AaronStiff <69512633+AaronStiff@users.noreply.github.com> Date: Tue, 9 May 2023 19:00:00 -0300 Subject: [PATCH 4/5] added changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f17a4a7e178..d3eeac146cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Fixed - Fixed another compatibility issue with Pandas 2.0, just affecting `px.*(line_close=True)` [[#4190](https://github.com/plotly/plotly.py/pull/4190)] - Added some rounding to the `make_subplots` function to handle situations where the user-input specs cause the domain to exceed 1 by small amounts https://github.com/plotly/plotly.py/pull/4153 + - Empty pandas dataframe with facet row/column set no longer fails [[#4038](https://github.com/plotly/plotly.py/pull/4038)] ## [5.14.1] - 2023-04-05 From 04029f6f2d0d664d15f99979ec996497cdc52e14 Mon Sep 17 00:00:00 2001 From: AaronStiff <69512633+AaronStiff@users.noreply.github.com> Date: Tue, 9 May 2023 21:19:29 -0300 Subject: [PATCH 5/5] black formatting --- test/percy/plotly-express.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/test/percy/plotly-express.py b/test/percy/plotly-express.py index 9d61708fbc5..49d3fdb8249 100644 --- a/test/percy/plotly-express.py +++ b/test/percy/plotly-express.py @@ -545,9 +545,4 @@ fig.write_html(os.path.join(dir_name, "timeline.html"), auto_play=False) -px.bar( - pd.DataFrame(columns=['A', 'B', 'X']), - x = 'A', - y = 'X', - facet_col = 'B' -) +px.bar(pd.DataFrame(columns=["A", "B", "X"]), x="A", y="X", facet_col="B")