Skip to content

Conversation

@my-tien
Copy link

@my-tien my-tien commented Jan 12, 2026

Description

Update SubplotidValidator to handle arrays of values.

Additional fix for closing #5463.

Changes

  • Handle arrays in SubplotidValidator

  • Added array_ok 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],
        legend=["legend", "legend2"],
    )
    
    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

Disclaimer I am required to add that…

the software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. in no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.

@my-tien
Copy link
Author

my-tien commented Jan 12, 2026

FYI @camdecoster @emilykl

Copy link
Contributor

@camdecoster camdecoster left a comment

Choose a reason for hiding this comment

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

This looks good, but there a few small changes to make. Thanks for the PR!

Comment on lines 1763 to 1768
desc = """\
The '{plotly_name}' property is an identifier of a particular
subplot, of type '{base}', that may be specified as the string '{base}'
optionally followed by an integer >= 1
(e.g. '{base}', '{base}1', '{base}2', '{base}3', etc.)
""".format(plotly_name=self.plotly_name, base=self.base)
Copy link
Contributor

Choose a reason for hiding this comment

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

You can remove this code since you redefined it below.

Suggested change

Comment on lines +1773 to +1775
- the string '{base}'
optionally followed by an integer >= 1
(e.g. '{base}', '{base}1', '{base}2', '{base}3', etc.)""".format(
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
- the string '{base}'
optionally followed by an integer >= 1
(e.g. '{base}', '{base}1', '{base}2', '{base}3', etc.)""".format(
- the string '{base}' optionally followed by an integer >= 1
(e.g. '{base}', '{base}1', '{base}2', '{base}3', etc.)""".format(

Comment on lines 1737 to 1738
"otherOpts": [
"regex"
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
"otherOpts": [
"arrayOk",
"regex"

Comment on lines +1784 to +1800
def coerce(value, invalid_els):
if not isinstance(value, str):
invalid_els.append(value)
return value
match = fullmatch(self.regex, value)
if not match:
is_valid = False
invalid_els.append(value)
return value
else:
digit_str = match.group(1)
if len(digit_str) > 0 and int(digit_str) == 0:
is_valid = False
invalid_els.append(value)
return value
elif len(digit_str) > 0 and int(digit_str) == 1:
# Remove 1 suffix (e.g. x1 -> x)
v = self.base
is_valid = True
return self.base
else:
is_valid = True
return value
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would make more sense to refactor this function to just check if the given input is a valid id. Then you could reference that in the if/then block. It feels weird to define invalid_els for the single value case.

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.

2 participants