<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Apr 14, 2014 at 11:59 AM, Chris Barker <span dir="ltr"><<a href="mailto:chris.barker@noaa.gov" target="_blank">chris.barker@noaa.gov</a>></span> wrote:<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>- datetime64 objects with high precision (e.g., ns) can't compare to datetime objects.</div></div></div></div></blockquote><div><br></div></div><div>


That's a problem, but how do you think it should be handled? My thought is that it should round to microseconds, and then compare -- kind of like comparing float32 and float64... </div></div></div></div></blockquote>
<div><br></div><div>I agree -- if the ns matter, you shouldn't be using datetime.datetime objects.</div><div><br></div><div>Similarly, it's currently not possible to convert high precision datetime64 objects into datetimes. Worse, this doesn't even raise an error!</div>
<div><br></div><div><font face="courier new, monospace">>>> from datetime import datetime</font></div><div><font face="courier new, monospace">>>> import numpy as np</font></div><div><font face="courier new, monospace">>>> np.datetime64('2000-01-01T00:00:00Z', 'us').astype(datetime)<br>
</font></div><div><pre style="padding:0px;font-size:14px;color:rgb(0,0,0);border-top-left-radius:0px;border-top-right-radius:0px;border-bottom-right-radius:0px;border-bottom-left-radius:0px;margin-top:0px;margin-bottom:0px;line-height:17.000059127807617px;word-break:break-all;word-wrap:break-word;white-space:pre-wrap;border:0px;vertical-align:baseline">
<font face="courier new, monospace">datetime.datetime(2000, 1, 1, 0, 0)</font></pre></div><div><div><font face="courier new, monospace">>>> np.datetime64('2000-01-01T00:00:00Z', 'ns').astype(datetime)<br>
</font></div><div></div></div><div><pre style="padding:0px;font-size:14px;color:rgb(0,0,0);border-top-left-radius:0px;border-top-right-radius:0px;border-bottom-right-radius:0px;border-bottom-left-radius:0px;margin-top:0px;margin-bottom:0px;line-height:17.000059127807617px;word-break:break-all;word-wrap:break-word;white-space:pre-wrap;border:0px;vertical-align:baseline">
<font face="courier new, monospace">946684800000000000L</font></pre><pre style="padding:0px;font-size:14px;color:rgb(0,0,0);border-top-left-radius:0px;border-top-right-radius:0px;border-bottom-right-radius:0px;border-bottom-left-radius:0px;margin-top:0px;margin-bottom:0px;line-height:17.000059127807617px;word-break:break-all;word-wrap:break-word;white-space:pre-wrap;border:0px;vertical-align:baseline">
<br></pre><pre style="padding:0px;border-top-left-radius:0px;border-top-right-radius:0px;border-bottom-right-radius:0px;border-bottom-left-radius:0px;margin-top:0px;margin-bottom:0px;word-break:break-all;word-wrap:break-word;border:0px;vertical-align:baseline">
<font face="arial, helvetica, sans-serif">Other inconsistent behavior:</font></pre><pre style="padding:0px;border-top-left-radius:0px;border-top-right-radius:0px;border-bottom-right-radius:0px;border-bottom-left-radius:0px;margin-top:0px;margin-bottom:0px;word-break:break-all;word-wrap:break-word;border:0px;vertical-align:baseline">
<br></pre><font face="courier new, monospace">>>> np.datetime64('2000', 'M')<br>numpy.datetime64('2000-01')<br>>>> np.datetime64('2000', 'D')<br>numpy.datetime64('2000-01-01')<br>
>>> np.datetime64('2000', 's')<br>---------------------------------------------------------------------------<br>TypeError                                 Traceback (most recent call last)<br><ipython-input-67-bf5fc9a2985b> in <module>()<br>
----> 1 np.datetime64('2000', 's')<br><br>TypeError: Cannot parse "2000" as unit 's' using casting rule 'same_kind'</font></div><div><font face="courier new, monospace"><br></font></div>
More broadly, my recommendation is to look through the unit tests for pandas' datetIme handling:</div><div class="gmail_quote"><div class="gmail_quote"><a href="https://github.com/pydata/pandas/tree/master/pandas/tseries/tests">https://github.com/pydata/pandas/tree/master/pandas/tseries/tests</a><br>
</div><div><br></div></div><div class="gmail_quote">Not everything is relevant but you might find some test cases you could borrow wholesale. Pandas is BSD licensed, so you may even be able to copy them directly into numpy.</div>
<div class="gmail_quote"><br></div><div class="gmail_quote">Best,</div><div class="gmail_quote">Stephan</div><div class="gmail_quote"><br></div></div></div>