Skip to content

Conversation

@camdecoster
Copy link
Contributor

@camdecoster camdecoster commented Jan 9, 2026

Description

Update BooleanValidator to handle arrays of values.

Addresses half of #5463. The other half is addressed by #5465.

Changes

  • Handle arrays in BooleanValidator
  • Add tests

Testing

  • Be on main
  • Run the following code:
    import plotly.graph_objects as go
    
    pie = go.Pie(
        labels=["A", "B", "C"],
        values=[65, 15, 20],
        showlegend=[True, False, False],
    )
    
    fig = go.Figure([pie], go.Layout())
    fig.show()
  • Note that a ValueError is raised
  • Switch to this branch
  • Run the same code again
  • Note that chart is rendered correctly

if isinstance(val, list):
assert val == v
else:
assert val == tuple(v)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert val == tuple(v)
assert list(val) == v

clearer IMO

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With your change, I removed the if/else block. Clearer indeed.

invalid_els = [e for e in v if not isinstance(e, bool)]
if invalid_els:
self.raise_invalid_elements(invalid_els[:10])
v = to_scalar_or_list(v)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not 100% sure whether this call to to_scalar_or_list() is necessary, but I don't think it will hurt.

Copy link
Contributor

@emilykl emilykl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

@camdecoster camdecoster merged commit 5a0440c into main Jan 13, 2026
9 of 10 checks passed
@camdecoster camdecoster deleted the cam/5463/handle-arrays-booleanvalidator branch January 13, 2026 22:04
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.

3 participants