Skip to content

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

Closed
wants to merge 1 commit into from
Closed

Value checking the numpoints argument to be a whole number. #6949

wants to merge 1 commit into from

Conversation

pfaion
Copy link

@pfaion pfaion commented Aug 16, 2016

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.

@@ -286,6 +286,13 @@ def __init__(self, parent, handles, labels,
ncol = 1
self._ncol = ncol

if (
Copy link
Member

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.

Copy link
Member

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

Copy link
Member

Choose a reason for hiding this comment

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

So it is 🐑

Copy link
Member

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)

@tacaswell tacaswell added this to the 2.0.1 (next bug fix release) milestone Aug 20, 2016
@phobson
Copy link
Member

phobson commented Apr 18, 2017

I think we can close this now

@tacaswell
Copy link
Member

Keeping some sort of validation, but via duck-typing, is still a good idea. Or just casting it to an int.

Copy link
Member

@tacaswell tacaswell left a 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.

@anntzer
Copy link
Contributor

anntzer commented Apr 18, 2017

I vote to let legend_handler take care of the validation, i.e. #8478 is enough IMO.

@QuLogic QuLogic modified the milestones: 2.0.1 (next bug fix release), 2.0.2 (next bug fix release) May 3, 2017
@pfaion pfaion closed this May 14, 2017
@pfaion pfaion deleted the numpoints-value-check branch May 14, 2017 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants