-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
bug: inconsistent types accepted in DateLocator subclasses #3897
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
Comments
it should include arrays. Tagging as 1.5 as this should be dealt with as part of an over-all overhaul of the date handling system. @cimarronm You have been working on the rrule code recently, is there a quick fix for this? |
As far as I can tell, there are two different things causing this problem. For For For I'm going to see if I can fix what I see as bugs in the dateutil code, but assuming that those are not in fact bugs (or that we want to support older versions of dateutil), for I think for now |
Looks like the bug giving problems with |
My PRs over at dateutil were accepted, and I tested this against what is now the master branch over there (as of this commit), and it resolves this issue, so eventually these issues will go away when matplotlib is built with I guess the next release of dateutil. If we want to support older versions of dateutil, like I said we can explicitly convert numpy arrays to lists of |
I think that makes sense to do (explicit conversion of numpy array to a On Sun, Dec 28, 2014 at 1:51 AM, Paul G. notifications@github.com wrote:
|
@WeatherGod Since I already made a lot of changes related to date handling, I can make the change in PR #3947. That said, I'm a bit ambivalent about doing this. It seems a bit strange to be doing dateutils' validation for it because of a bug in the current version. If I could think of any potential consequences other than the almost certainly negligible performance hit, I'd probably advocate just adding a note in the documentation that these specific locators don't accept numpy arrays when matplotlib was built with dateutils <= 2.3. Since we don't seem to be making any library calls ourselves using numpy arrays, this gives the user the choice of whether to switch the data type of their sequence or upgrade dateutils. |
OK, I've implemented it in the latest revision to #3947. |
By the way, this was fixed ages ago, both in matplotlib and dateutil. Here's a MWE, run with a deliberately old version of dateutil: import matplotlib
import matplotlib.dates as m_dates
import numpy as np
import dateutil
print("Matplotlib version: {}".format(matplotlib.__version__))
print("Numpy version: {}".format(np.__version__))
print("Dateutil version: {}".format(dateutil.__version__))
print("DayLocator: Used to fail")
m_dates.DayLocator(np.arange(2, 13, 2))
print("HourLocator: Used to succeed")
m_dates.HourLocator(np.arange(2, 13, 2))
print("MonthLocator: Used to fail")
m_dates.MinuteLocator(np.arange(2, 13, 2))
print("SecondLocator: Used to succeed")
m_dates.SecondLocator(np.arange(2,13,2))
print("WeekdayLocator: Used to fail")
m_dates.WeekdayLocator(np.arange(2,13,2))
print("MonthLocator as list: Used to succeed")
m_dates.MonthLocator(np.arange(2,13,2).tolist())
print("All good!") Results:
Does this need tests before the issue can be closed? |
Nope, this is good enough! Thanks for going through old issues. |
I've usually used np arrays, mostly out of habit, to construct my HourLocator and MinuteLocator objects, and today I was surprised to find that this did not work for MonthLocator objects. I also tested DayLocator and WeekdayLocator and found that they did not work with np arrays. The mpl docs suggest that the arguments can be "an int or sequence" -- not sure if this would include np arrays or not.
Not a big deal, but it did confuse me for a few minutes.
The text was updated successfully, but these errors were encountered: