Skip to content

Commit 50bb20b

Browse files
authored
Merge pull request #5625 from eugen-goebel/fix-4654-marginal-error-message
Raise a clear error for unsupported marginal plot types
2 parents 2a91b77 + 2f2236c commit 50bb20b

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
44

55
## Unreleased
66

7+
### Fixed
8+
- 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)], with thanks to @eugen-goebel for the contribution!
9+
710

811
## [6.8.0] - 2026-06-03
912

‎plotly/express/_core.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,11 @@ def make_trace_spec(args, constructor, attrs, trace_patch):
971971
),
972972
marginal=letter,
973973
)
974+
else:
975+
raise ValueError(
976+
f"Invalid value '{args['marginal_' + letter]}' for `marginal_{letter}`."
977+
"Supported marginal plot types are: 'rug', 'box', 'violin', 'histogram'."
978+
)
974979
if "color" in attrs or "color" not in args:
975980
if "marker" not in trace_spec.trace_patch:
976981
trace_spec.trace_patch["marker"] = dict()

‎tests/test_optional/test_px/test_marginals.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,15 @@ def test_single_marginals(backend, px_fn, marginal, orientation):
2424
df, x="total_bill", y="total_bill", marginal=marginal, orientation=orientation
2525
)
2626
assert len(fig.data) == 1 + (marginal is not None)
27+
28+
29+
def test_unsupported_marginal_raises_clear_error(): # issue 4654
30+
# An unsupported marginal type used to fail deep inside make_figure with a
31+
# cryptic "'NoneType' object has no attribute 'constructor'". It should
32+
# instead raise a clear error naming the supported values.
33+
with pytest.raises(ValueError, match="Supported marginal plot types"):
34+
px.scatter(x=[1, 2, 3], y=[2, 3, 4], marginal_x="density")
35+
with pytest.raises(ValueError, match="Supported marginal plot types"):
36+
px.scatter(x=[1, 2, 3], y=[2, 3, 4], marginal_y="density")
37+
with pytest.raises(ValueError, match="Supported marginal plot types"):
38+
px.histogram(x=[1, 2, 3], marginal="density")

0 commit comments

Comments
 (0)