<p dir="auto"><em>Original ticket <a href="http://projects.scipy.org/numpy/ticket/1304" rel="nofollow">http://projects.scipy.org/numpy/ticket/1304</a> on 2009-11-25 by trac user dyamins, assigned to unknown.</em></p>
<p dir="auto">np.dtype won't accept '|S0' as a type argument.</p>
<blockquote>
<blockquote>
<blockquote>
<p dir="auto">np.dtype('|S0')<br>
TypeError: data type not understood</p>
</blockquote>
</blockquote>
</blockquote>
<p dir="auto">I have to do something like this:</p>
<blockquote>
<blockquote>
<blockquote>
<p dir="auto">d = np.dtype('|S')</p>
<p dir="auto">d<br>
dtype('|S0')</p>
</blockquote>
</blockquote>
</blockquote>
<p dir="auto">to get what I want.   Is this intended?  Regardless, this inconsistency also means that things like:</p>
<blockquote>
<blockquote>
<blockquote>
<p dir="auto">np.dtype(d.descr)</p>
</blockquote>
</blockquote>
</blockquote>
<p dir="auto">can fail even when d is a properly constructed dtype object with a '|S0' type, which seems a little perverse.</p>
<p dir="auto"><em>Original ticket <a href="http://projects.scipy.org/numpy/ticket/1239" rel="nofollow">http://projects.scipy.org/numpy/ticket/1239</a> on 2009-09-24 by <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/dwf/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/dwf">@dwf</a>, assigned to <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/charris/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/charris">@charris</a>.</em></p>
<p dir="auto">I noticed this inconsistency:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In [30]: dtype(str)
Out[30]: dtype('|S0')

In [31]: dtype('|S0')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

/Users/dwf/&lt;ipython console&gt; in &lt;module&gt;()

TypeError: data type not understood

In [32]: dtype(unicode)
Out[32]: dtype('&gt;U0')

In [33]: dtype('&gt;U0')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

/Users/dwf/&lt;ipython console&gt; in &lt;module&gt;()

TypeError: data type not understood"><pre class="notranslate"><code class="notranslate">In [30]: dtype(str)
Out[30]: dtype('|S0')

In [31]: dtype('|S0')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

/Users/dwf/&lt;ipython console&gt; in &lt;module&gt;()

TypeError: data type not understood

In [32]: dtype(unicode)
Out[32]: dtype('&gt;U0')

In [33]: dtype('&gt;U0')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

/Users/dwf/&lt;ipython console&gt; in &lt;module&gt;()

TypeError: data type not understood
</code></pre></div>
<p dir="auto">This would present problems if you, say, np.save()'d an array with an S0 field and tried to np.load() it back; dtype() would choke in the deserialization process.</p>
<p dir="auto">The attached patch resolves it in the simplest way I could think of: for U and S typecodes, 0-length is okay (note that '&gt;U0' and '&lt;U0' are still different types, technically, despite byte order being meaningless here.</p>