-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Value checking the numpoints argument to be a whole number. #6949
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
Conversation
@@ -286,6 +286,13 @@ def __init__(self, parent, handles, labels, | |||
ncol = 1 | |||
self._ncol = ncol | |||
|
|||
if ( |
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.
It is probably better to do something like if int(n) != n: raise
.
Should probably make numpoints
a property and do the validation on the way in as well.
This should probably also check that numpoints > 0.
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 check for numpoints > 0 is just below
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.
So it is 🐑
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.
Also see discussion at #6955 (diff)
I think we can close this now |
Keeping some sort of validation, but via duck-typing, is still a good idea. Or just casting it to an int. |
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.
Do not use explicit type checking here.
I vote to let legend_handler take care of the validation, i.e. #8478 is enough IMO. |
Referencing issue #6921, if you accidentally provide a decimal fraction as numpoints, you get a strange error in another file (https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/legend_handler.py#L151) not reflecting the real problem. This can be fixed by checking for whole numbers.
I included checking for whole floats as well, in case the value gets calculated through some floating point formula. If that doesn't make any sense, I can remove it again.