<p dir="auto">Converting ns/as-precisiong datetime64 to datetime.datetime results in integer:</p>
<p dir="auto"><code class="notranslate">datetime.datetime</code> does not support nanoseconds (<a href="http://bugs.python.org/issue15443" rel="nofollow">see issue</a>).  When numpy casts it should round or raise an error, instead it silently returns int:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In [186]: numpy.datetime64(&quot;1985-08-13&quot;, &quot;us&quot;).astype(datetime.datetime)
Out[186]: datetime.datetime(1985, 8, 13, 0, 0)

In [187]: numpy.datetime64(&quot;1985-08-13&quot;, &quot;ns&quot;).astype(datetime.datetime)
Out[187]: 492739200000000000

In [189]: numpy.datetime64(&quot;1985-08-13&quot;, &quot;as&quot;).astype(datetime.datetime)
Out[189]: -8200712707674996736"><pre class="notranslate"><code class="notranslate">In [186]: numpy.datetime64("1985-08-13", "us").astype(datetime.datetime)
Out[186]: datetime.datetime(1985, 8, 13, 0, 0)

In [187]: numpy.datetime64("1985-08-13", "ns").astype(datetime.datetime)
Out[187]: 492739200000000000

In [189]: numpy.datetime64("1985-08-13", "as").astype(datetime.datetime)
Out[189]: -8200712707674996736
</code></pre></div>
<p dir="auto">The dtype <code class="notranslate">np.object_</code> is the most general catch-all type to contain arbitrary python objects. As such, <code class="notranslate">.astype(object)</code> should preferably not upcast, but certainly never <em>down</em>cast:</p>
<h3 dir="auto">Reproducing code example:</h3>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; import numpy as np
&gt;&gt;&gt; arr = np.array([10 ** 18], dtype='M8[ns]')
&gt;&gt;&gt; arr
array(['2001-09-09T01:46:40.000000000'], dtype='datetime64[ns]')
&gt;&gt;&gt; arr[0]
numpy.datetime64('2001-09-09T01:46:40.000000000')
&gt;&gt;&gt; arr.astype(object)
array([1000000000000000000], dtype=object)
&gt;&gt;&gt; arr.astype(object)[0]
1000000000000000000"><pre class="notranslate"><span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">arr</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">array</span>([<span class="pl-c1">10</span> <span class="pl-c1">**</span> <span class="pl-c1">18</span>], <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s">'M8[ns]'</span>)
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">arr</span>
<span class="pl-en">array</span>([<span class="pl-s">'2001-09-09T01:46:40.000000000'</span>], <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s">'datetime64[ns]'</span>)
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">arr</span>[<span class="pl-c1">0</span>]
<span class="pl-s1">numpy</span>.<span class="pl-en">datetime64</span>(<span class="pl-s">'2001-09-09T01:46:40.000000000'</span>)
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">arr</span>.<span class="pl-en">astype</span>(<span class="pl-s1">object</span>)
<span class="pl-en">array</span>([<span class="pl-c1">1000000000000000000</span>], <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">object</span>)
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">arr</span>.<span class="pl-en">astype</span>(<span class="pl-s1">object</span>)[<span class="pl-c1">0</span>]
<span class="pl-c1">1000000000000000000</span></pre></div>
<p dir="auto">The expected outcome for the last two lines is:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; arr.astype(object)
array([numpy.datetime64('2001-09-09T01:46:40.000000000')], dtype=object)
&gt;&gt;&gt; arr.astype(object)[0]
numpy.datetime64('2001-09-09T01:46:40.000000000')"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; arr.astype(object)
array([numpy.datetime64('2001-09-09T01:46:40.000000000')], dtype=object)
&gt;&gt;&gt; arr.astype(object)[0]
numpy.datetime64('2001-09-09T01:46:40.000000000')
</code></pre></div>
<p dir="auto">as well as</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; arr.astype(object)[0] == arr[0]
True"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; arr.astype(object)[0] == arr[0]
True
</code></pre></div>
<h3 dir="auto">Numpy/Python version information:</h3>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="numpy: 1.15.4
python: 3.7.1"><pre class="notranslate"><code class="notranslate">numpy: 1.15.4
python: 3.7.1
</code></pre></div>