-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add array_ok to SubplotidValidator, used in pie.legend #5465
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
FYI @camdecoster @emilykl |
camdecoster
left a comment
There was a problem hiding this 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!
| 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) |
There was a problem hiding this comment.
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.
| - the string '{base}' | ||
| optionally followed by an integer >= 1 | ||
| (e.g. '{base}', '{base}1', '{base}2', '{base}3', etc.)""".format( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| - 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( |
| "otherOpts": [ | ||
| "regex" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| "otherOpts": [ | |
| "arrayOk", | |
| "regex" |
| 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 |
There was a problem hiding this comment.
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.
Description
Update
SubplotidValidatorto handle arrays of values.Additional fix for closing #5463.
Changes
Handle arrays in
SubplotidValidatorAdded array_ok tests
Testing
Be on main
Run the following code:
Note that a
ValueErroris raisedSwitch 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.