Skip to content

fix: Handle arrays in BooleanValidator - #5464

Merged
camdecoster merged 2 commits into
mainfrom
cam/5463/handle-arrays-booleanvalidator
Jan 13, 2026
Merged

camdecoster merged 2 commits into
mainfrom
cam/5463/handle-arrays-booleanvalidator

Conversation

@camdecoster

@camdecoster camdecoster commented Jan 9, 2026 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

@emilykl emilykl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants