Skip to content

added: ignore facet args with empty dataset #4038

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,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)]
- Empty pandas dataframe with facet row/column set no longer fails [[#4038](https://github.com/plotly/plotly.py/pull/4038)]
- 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 [[#4153](https://github.com/plotly/plotly.py/pull/4153)]
- Sanitize JSON output to prevent an XSS vector when graphs are inserted directly into HTML [[#4196](https://github.com/plotly/plotly.py/pull/4196)]
- Fixed issue with shapes and annotations plotting on the wrong y axis when supplied with a specific axis in the `yref` parameter [[#4177](https://github.com/plotly/plotly.py/pull/4177)]
Expand Down
4 changes: 4 additions & 0 deletions packages/python/plotly/plotly/express/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1880,6 +1880,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
Expand Down
3 changes: 3 additions & 0 deletions test/percy/plotly-express.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,3 +543,6 @@
)
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")