<p dir="auto">It seems that <code class="notranslate">np.vectorize</code> casts / unboxes <code class="notranslate">timedelta64</code> values and does so kind of inconsistently depending on the unit. I am not sure that this was intentional, but makes it difficult to work with such arrays; in particular, it is not possible to vectorize a function which takes <code class="notranslate">timedelta64</code> value;</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; np.__version__
'1.9.0'
&gt;&gt;&gt; f = lambda x: print(type(x), x)
&gt;&gt;&gt; xs = np.arange(1, 3).astype('timedelta64[h]')
&gt;&gt;&gt; xs
array([1, 2], dtype='timedelta64[h]')"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; np.__version__
'1.9.0'
&gt;&gt;&gt; f = lambda x: print(type(x), x)
&gt;&gt;&gt; xs = np.arange(1, 3).astype('timedelta64[h]')
&gt;&gt;&gt; xs
array([1, 2], dtype='timedelta64[h]')
</code></pre></div>
<p dir="auto">with <code class="notranslate">[h]</code> and <code class="notranslate">[s]</code> unit:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; _ = np.vectorize(f)(xs)
&lt;class 'numpy.timedelta64'&gt; 1 hours
&lt;class 'datetime.timedelta'&gt; 1:00:00
&lt;class 'datetime.timedelta'&gt; 2:00:00
&gt;&gt;&gt; _ = np.vectorize(f)(xs.astype('timedelta64[s]'))
&lt;class 'numpy.timedelta64'&gt; 3600 seconds
&lt;class 'datetime.timedelta'&gt; 1:00:00
&lt;class 'datetime.timedelta'&gt; 2:00:00
&gt;&gt;&gt; _ = np.vectorize(f, otypes='O')(xs.astype('timedelta64[s]'))
&lt;class 'datetime.timedelta'&gt; 1:00:00
&lt;class 'datetime.timedelta'&gt; 2:00:00"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; _ = np.vectorize(f)(xs)
&lt;class 'numpy.timedelta64'&gt; 1 hours
&lt;class 'datetime.timedelta'&gt; 1:00:00
&lt;class 'datetime.timedelta'&gt; 2:00:00
&gt;&gt;&gt; _ = np.vectorize(f)(xs.astype('timedelta64[s]'))
&lt;class 'numpy.timedelta64'&gt; 3600 seconds
&lt;class 'datetime.timedelta'&gt; 1:00:00
&lt;class 'datetime.timedelta'&gt; 2:00:00
&gt;&gt;&gt; _ = np.vectorize(f, otypes='O')(xs.astype('timedelta64[s]'))
&lt;class 'datetime.timedelta'&gt; 1:00:00
&lt;class 'datetime.timedelta'&gt; 2:00:00
</code></pre></div>
<p dir="auto">with <code class="notranslate">[ns]</code> unit:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; _ = np.vectorize(f)(xs.astype('timedelta64[ns]'))
&lt;class 'numpy.timedelta64'&gt; 3600000000000 nanoseconds
&lt;class 'int'&gt; 3600000000000
&lt;class 'int'&gt; 7200000000000
&gt;&gt;&gt; _ = np.vectorize(f, otypes='O')(xs.astype('timedelta64[ns]'))
&lt;class 'int'&gt; 3600000000000
&lt;class 'int'&gt; 7200000000000"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; _ = np.vectorize(f)(xs.astype('timedelta64[ns]'))
&lt;class 'numpy.timedelta64'&gt; 3600000000000 nanoseconds
&lt;class 'int'&gt; 3600000000000
&lt;class 'int'&gt; 7200000000000
&gt;&gt;&gt; _ = np.vectorize(f, otypes='O')(xs.astype('timedelta64[ns]'))
&lt;class 'int'&gt; 3600000000000
&lt;class 'int'&gt; 7200000000000
</code></pre></div>
<p dir="auto"><em>Original ticket <a href="http://projects.scipy.org/numpy/ticket/1173" rel="nofollow">http://projects.scipy.org/numpy/ticket/1173</a> on 2009-07-15 by <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/stsci-sienkiew/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/stsci-sienkiew">@stsci-sienkiew</a>, assigned to <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/pierregm/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/pierregm">@pierregm</a>.</em></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="======================================================================
FAIL: Tests new ufuncs on MaskedArrays.
----------------------------------------------------------------------
Traceback (most recent call last):
  File &quot;/usr/ra/pyssg/2.5.1/numpy/ma/tests/test_core.py&quot;, line 1403, in test_testUfuncRegression
    assert_mask_equal(ur.mask, mr.mask)
  File &quot;/usr/stsci/pyssgdev/2.5.1/numpy/ma/testutils.py&quot;, line 237, in assert_mask_equal
    assert_array_equal(m1, m2)
  File &quot;/usr/stsci/pyssgdev/2.5.1/numpy/ma/testutils.py&quot;, line 193, in assert_array_equal
    header='Arrays are not equal')
  File &quot;/usr/stsci/pyssgdev/2.5.1/numpy/ma/testutils.py&quot;, line 186, in assert_array_compare
    verbose=verbose, header=header)
  File &quot;/usr/stsci/pyssgdev/2.5.1/numpy/testing/utils.py&quot;, line 395, in assert_array_compare
    raise AssertionError(msg)
AssertionError: 
Arrays are not equal

(mismatch 25.0%)
 x: array([False,  True, False,  True, False, False, False,  True], dtype=bool)
 y: array([False,  True, False, False, False, False, False, False], dtype=bool)"><pre class="notranslate"><code class="notranslate">======================================================================
FAIL: Tests new ufuncs on MaskedArrays.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/ra/pyssg/2.5.1/numpy/ma/tests/test_core.py", line 1403, in test_testUfuncRegression
    assert_mask_equal(ur.mask, mr.mask)
  File "/usr/stsci/pyssgdev/2.5.1/numpy/ma/testutils.py", line 237, in assert_mask_equal
    assert_array_equal(m1, m2)
  File "/usr/stsci/pyssgdev/2.5.1/numpy/ma/testutils.py", line 193, in assert_array_equal
    header='Arrays are not equal')
  File "/usr/stsci/pyssgdev/2.5.1/numpy/ma/testutils.py", line 186, in assert_array_compare
    verbose=verbose, header=header)
  File "/usr/stsci/pyssgdev/2.5.1/numpy/testing/utils.py", line 395, in assert_array_compare
    raise AssertionError(msg)
AssertionError: 
Arrays are not equal

(mismatch 25.0%)
 x: array([False,  True, False,  True, False, False, False,  True], dtype=bool)
 y: array([False,  True, False, False, False, False, False, False], dtype=bool)
</code></pre></div>
<p dir="auto">numpy 1.4.0.dev7132</p>
<p dir="auto">solaris 8</p>
<p dir="auto">python 2.5.1</p>