-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
DOC: Better error when float on datetime axis #10084
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
lib/matplotlib/dates.py
Outdated
|
||
if dmin < 1: | ||
raise ValueError('datalim minimum {} < 1. This often ' | ||
'happens if you pass a float to an ' |
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.
indent
lib/matplotlib/dates.py
Outdated
raise ValueError('cannot convert {} < 1 to a date. This ' | ||
'often happens if floats are passed to ' | ||
'a Matplotlib axis that expects datetime objects. ' | ||
''.format(ix)) |
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 don't need the ''
, starting the line with a dot binds to the string on the previous line
lib/matplotlib/dates.py
Outdated
if ix < 1: | ||
raise ValueError('cannot convert {} < 1 to a date. This ' | ||
'often happens if floats are passed to ' | ||
'a Matplotlib axis that expects datetime objects. ' |
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.
to an axis (no need to mpl, which you also did not include 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.
minor formatting/wording can be improved but nothing blocking
f02880f
to
50969c4
Compare
lib/matplotlib/dates.py
Outdated
|
||
if dmin < 1: | ||
raise ValueError('datalim minimum {} < 1. This often ' | ||
'happens if you pass a float to an ' |
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.
Can "float" be change to something less technical like "number" or "normal number"?
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.
value that is not a datetime?
(apart from my suggested change I am +10000 on this, since I remember in my early Matplotlib days spending ages meaning what on earth the current error message meant) |
Yep I’ll fix it this pm. No problem making it even clearer. |
50969c4
to
88a19c2
Compare
Done - I couldn't get a test to work, however. 🐑 If I do: g, ax = plt.subplots()
ax.plot(datetime(2017, 1, 1), 1)
ax.plot(1, 1)
fig.draw(fig.canvas.get_renderer()) I get the error. Trying to do this in
|
lib/matplotlib/dates.py
Outdated
@@ -282,6 +283,11 @@ def _from_ordinalf(x, tz=None): | |||
tz = _get_rc_timezone() | |||
|
|||
ix = int(x) | |||
if ix < 1: | |||
raise ValueError('cannot convert {} < 1 to a date. This ' |
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 should be:
cannot convert {} to a date
{} < 1
evaluate to a bool 😉
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.
OK. Changed to
'view limit minimum {} is less than 1 and '
'is an invalid Matplotlib date value. This '
'often happens if you pass a non-datetime '
'value to an axis that has datetime units'
.format(vmin))
88a19c2
to
38b137b
Compare
38b137b
to
a4759e8
Compare
PR Summary
#9211 points out that the error message after
yields the mysterious error:
This PR catches earlier and returns:
PR Checklist