Skip to content

Raise a clear error for unsupported marginal plot types#5625

Open
eugen-goebel wants to merge 2 commits into
plotly:mainfrom
eugen-goebel:fix-4654-marginal-error-message
Open

Raise a clear error for unsupported marginal plot types#5625
eugen-goebel wants to merge 2 commits into
plotly:mainfrom
eugen-goebel:fix-4654-marginal-error-message

Conversation

@eugen-goebel

Copy link
Copy Markdown

Link to issue

Closes #4654

Description of change

make_trace_spec now raises a clear ValueError listing the supported marginal plot types when an unsupported value is passed to marginal_x, marginal_y or marginal, instead of failing later with a cryptic 'NoneType' object has no attribute 'constructor'.

Demo

Before:

>>> import plotly.express as px
>>> px.scatter(x=[1, 2, 3], y=[2, 3, 4], marginal_x="density")
AttributeError: 'NoneType' object has no attribute 'constructor'

After:

>>> import plotly.express as px
>>> px.scatter(x=[1, 2, 3], y=[2, 3, 4], marginal_x="density")
ValueError: Invalid value 'density' for `marginal_x`. Supported marginal plot types are: 'rug', 'box', 'violin', 'histogram'.

Testing strategy

Adds test_unsupported_marginal_raises_clear_error in tests/test_optional/test_px/test_marginals.py, which asserts that an unsupported value for marginal_x, marginal_y and the singular marginal argument raises a ValueError. The existing marginal tests still pass.

Additional information (optional)

The singular marginal argument is normalised to marginal_x / marginal_y before make_trace_spec runs, so a single check covers all three parameters.

Guidelines

Closes plotly#4654.

Passing an unsupported value to marginal_x, marginal_y or marginal in
Plotly Express (for example marginal_x="density") left trace_spec as None
in make_trace_spec, which later failed deep inside make_figure with a
confusing "'NoneType' object has no attribute 'constructor'".

make_trace_spec now raises a ValueError naming the offending value and
listing the supported marginal plot types: rug, box, violin and
histogram. The singular `marginal` argument is normalised to marginal_x
or marginal_y before this point, so the single check covers all three
parameters.

Adds a regression test in tests/test_optional/test_px/test_marginals.py.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

clarify error message when using unsupported marginal plot type

1 participant