X Tutup
Skip to content

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

Closed
pfaion wants to merge 1 commit intomatplotlib:masterfrom
pfaion:numpoints-value-check
Closed

Value checking the numpoints argument to be a whole number.#6949
pfaion wants to merge 1 commit intomatplotlib:masterfrom
pfaion:numpoints-value-check

Conversation

@pfaion
Copy link
Copy Markdown

@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.

ncol = 1
self._ncol = ncol

if (
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

phobson commented Apr 18, 2017

I think we can close this now

@tacaswell
Copy link
Copy Markdown
Member

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

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

X Tutup