Skip to content
Open
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

### Fixed
- Raise a clear `ValueError` when an unsupported marginal plot type is passed to Plotly Express, instead of failing later with a cryptic `'NoneType' object has no attribute 'constructor'` message [[#5625](https://github.com/plotly/plotly.py/pull/5625)]


## [6.8.0] - 2026-06-03

Expand Down
6 changes: 6 additions & 0 deletions plotly/express/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,12 @@ def make_trace_spec(args, constructor, attrs, trace_patch):
),
marginal=letter,
)
else:
raise ValueError(
"Invalid value '%s' for `marginal_%s`. Supported marginal "
"plot types are: 'rug', 'box', 'violin', 'histogram'."
% (args["marginal_" + letter], letter)
)
if "color" in attrs or "color" not in args:
if "marker" not in trace_spec.trace_patch:
trace_spec.trace_patch["marker"] = dict()
Expand Down
12 changes: 12 additions & 0 deletions tests/test_optional/test_px/test_marginals.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,15 @@ def test_single_marginals(backend, px_fn, marginal, orientation):
df, x="total_bill", y="total_bill", marginal=marginal, orientation=orientation
)
assert len(fig.data) == 1 + (marginal is not None)


def test_unsupported_marginal_raises_clear_error(): # issue 4654
# An unsupported marginal type used to fail deep inside make_figure with a
# cryptic "'NoneType' object has no attribute 'constructor'". It should
# instead raise a clear error naming the supported values.
with pytest.raises(ValueError, match="Supported marginal plot types"):
px.scatter(x=[1, 2, 3], y=[2, 3, 4], marginal_x="density")
with pytest.raises(ValueError, match="Supported marginal plot types"):
px.scatter(x=[1, 2, 3], y=[2, 3, 4], marginal_y="density")
with pytest.raises(ValueError, match="Supported marginal plot types"):
px.histogram(x=[1, 2, 3], marginal="density")