-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
FIX: datetime64 now recognized if in a list #12277
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
FIX: datetime64 now recognized if in a list #12277
Conversation
Hmm, I wonder if converting lists of unitized data is something we need to fix more generally; I had to fix it manually in the Astropy converters too: astropy/astropy#7037 |
I'm not sure we can make all the lists ndarrays. OTOH, we can decide to not make our own functions return lists. The issue here is that this internal helper returns a list, whereas it'd be nice if it returned an array. matplotlib/lib/matplotlib/axes/_axes.py Lines 3144 to 3153 in b329c77
|
Yeah, I was wondering if the unit machinery should be able to cope with lists of units (which as you say are often used internally), independently of particular |
I don't know - I don't see an easy way to do that, except right in |
b4f0492
to
8ac27ac
Compare
@dstansby Thinkng about this more, I think this will be really hard. Suppose we pass a complicated structure to a converter. I don't think we should stop the ConversionInterface from accepting that structure if we can't premassage it into an ndarray. Thats what the converter is supposed to do. Our current difficulty is that we accept a lot of ways of packing data by default. I'd argue we could be more strict about this. But in the case of #12271 the form that was being passed worked for |
lib/matplotlib/dates.py
Outdated
else: | ||
d = np.asarray(d) | ||
if (isinstance(d, np.ndarray) and |
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.
The first part of this will always be true here, I think we only need the second part of the if statement.
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.
Agree.... Fixed...
if not np.iterable(d): | ||
if (isinstance(d, np.datetime64) or (isinstance(d, np.ndarray) and |
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 don't think that we will ever hit the second half of this conditional as
In [5]: np.iterable(np.arange(5))
Out[5]: True
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.
t0 = datetime.datetime(2017, 1, 1, 0, 1, 1)
tnp = np.array(t0, dtype='datetime64[us]')
print(np.iterable(tnp))
returns False
(believe it or not)...
👍 in principle, left a few comments on the conditionals, but not going to block merging over this. I only think this needs to be backported to 3.0.x as this is something the user can work-around in userspace (by casting to a numpy array) so this does not pass the critical threshold (ex, import failure, segfault). |
8ac27ac
to
5038bd7
Compare
5038bd7
to
86d3257
Compare
Thanks @tacaswell |
Owee, I'm MrMeeseeks, Look at me. There seem to be a conflict, please backport manually. Here are approximate instructions:
And apply the correct labels and milestones. Congratulation you did some good work ! Hopefully your backport PR will be tested by the continuous integration and merged soon! If these instruction are inaccurate, feel free to suggest an improvement. |
…v3.0.x Backport PR #12277: FIX: datetime64 now recognized if in a list
PR Summary
ax.errorbar
sends a list of x values toline
, but the new datetime64 converter was not being called on a bare list of datetime64 objects (they had to be packed in an ndarray). This now checks the list elements too...Closes #12271
Fails on master, and passes w/ this PR.
PR Checklist