Skip to content
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

Add parameter checks to DayLocator initiator #6955

Merged
merged 4 commits into from Aug 22, 2016

Conversation

LindyBalboa
Copy link
Contributor

Check that interval parameter is an integer greater than zero.

Delete unuseful 'optimization' meant to prevent exceeding the
MAXTICKS variable. During testing it seemed ineffective. The
following Locator.raise_if_exceeds exception was triggered first
anyways.

resolves #6935

@@ -1254,6 +1241,12 @@ def __init__(self, bymonthday=None, interval=1, tz=None):

Default is to tick every day of the month: ``bymonthday=range(1,32)``
"""
if interval < 1:
raise ValueError("The interval parameter must be an integer "
Copy link
Member

@story645 story645 Aug 18, 2016

Choose a reason for hiding this comment

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

since these are distinct errors, the messages should probabably be unique:
interval < 1 : The interval must be greater than 0
isinstance(interval, int): the interval must be an integer
(and also, this should then maybe be a TypeError?)
Otherwise you may as well do if interval <1 or not isinstance(interval, int)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense. I thought of both cases. On the one hand, I feel since the parameter is being addressed anyways, it is worthwhile to flat out say both limitations. But on the other, if interval <1 or not isinstance(interval, int) started looking a little full. I figured it was best to just open the PR and get feedback.

I think it is still the better option. I will consolidate it to one check/one exception.

@LindyBalboa
Copy link
Contributor Author

LindyBalboa commented Aug 19, 2016

I'm confused as to what happened to the one Travis build. Someone mind taking a look?

I reran the mathtext test locally and it was no problem.

@@ -1254,6 +1241,8 @@ def __init__(self, bymonthday=None, interval=1, tz=None):

Default is to tick every day of the month: ``bymonthday=range(1,32)``
"""
if not isinstance(interval, int) or interval < 1:
Copy link
Member

Choose a reason for hiding this comment

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

This will fail on internal == 1.0 which is surprising. I think if not interval == int(interval) is a better test here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is a fair point, but for a day locator, does that really make sense? I personally think it would be better to enforce the typing in this specific case.

Unless you think it would be a problem with existing code bases, then I suppose catering to compatibility would be preferred.

Copy link
Member

Choose a reason for hiding this comment

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

It has a chance of breaking user code. This also breaks in the case of non-python ints, ex

In [56]: d = np.uint8(5)

In [57]: isinstance(d, int)
Out[59]: False

In [60]: d == int(d)
Out[60]: True

isinstance should only be used when there is no other reasonable option.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aha yes that makes sense, especially with the numpy example. I remember now having some nightmares with Qt qints in an old app. I will get that fixed up in the morning.

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

For reasons un-known the math text tests are flaky, restarted the tests.

Check that interval parameter is an integer greater than zero.

Delete unuseful 'optimization' meant to prevent exceeding the
MAXTICKS variable. During testing it seemed ineffective. The
following Locator.raise_if_exceeds exception was triggered first
anyways.

resolves matplotlib#6935
@tacaswell
Copy link
Member

Looks good. Can you add a test for that exception being raised on invalid input?

@tacaswell tacaswell merged commit a53c4b3 into matplotlib:master Aug 22, 2016
tacaswell added a commit that referenced this pull request Aug 22, 2016
MNT: Add parameter checks to DayLocator initiator
@tacaswell
Copy link
Member

backported to V2.x as 125a296

@QuLogic QuLogic modified the milestones: 2.0 (style change major release), 2.0.1 (next bug fix release) Aug 22, 2016
@LindyBalboa LindyBalboa deleted the issue_6935 branch August 22, 2016 20:16
@silenceliang
Copy link

silenceliang commented Jan 11, 2018

modify lib/matplotlib/ticker.py
this works!

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.

matplotlib.dates.DayLocator cannot handle invalid input
6 participants