<p dir="auto">When testing if the dtype of an array is present in a set of dtypes, the answer is unexpected.</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="import numpy as np
f32_dtype = np.zeros(1, dtype=np.float32).dtype

# test with list of dtypes
print(f32_dtype in [np.float32, np.uint8])  # =&gt; True (as expected)

# test with set of dtypes
print(f32_dtype in {np.float32, np.uint8})  # =&gt; False (not as expected)"><pre class="notranslate"><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-s1">f32_dtype</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">zeros</span>(<span class="pl-c1">1</span>, <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">np</span>.<span class="pl-s1">float32</span>).<span class="pl-s1">dtype</span>

<span class="pl-c"># test with list of dtypes</span>
<span class="pl-en">print</span>(<span class="pl-s1">f32_dtype</span> <span class="pl-c1">in</span> [<span class="pl-s1">np</span>.<span class="pl-s1">float32</span>, <span class="pl-s1">np</span>.<span class="pl-s1">uint8</span>])  <span class="pl-c"># =&gt; True (as expected)</span>

<span class="pl-c"># test with set of dtypes</span>
<span class="pl-en">print</span>(<span class="pl-s1">f32_dtype</span> <span class="pl-c1">in</span> {<span class="pl-s1">np</span>.<span class="pl-s1">float32</span>, <span class="pl-s1">np</span>.<span class="pl-s1">uint8</span>})  <span class="pl-c"># =&gt; False (not as expected)</span></pre></div>

<h3 dir="auto">Error message:</h3>
<p dir="auto">none</p>
<h3 dir="auto">Numpy/Python version information:</h3>
<p dir="auto">numpy 1.18.4<br>
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)]</p>
<h2 dir="auto">Summary</h2>
<p dir="auto">Make DType objects, their corresponding types, and their string names all compare unequal.</p>
<h2 dir="auto">Historical issue</h2>
<p dir="auto">For some reason, <code class="notranslate">dtype</code> objects and the numpy types they are based off of compare equal.  They don't hash equal of course, which goes against Python's docs that say</p>
<blockquote>
<p dir="auto">The only required property is that objects which compare equal have the same hash value…</p>
</blockquote>
<p dir="auto">Can we make them compare unequal?  Is there any reason for them to compare equal?</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In [6]: np.dtype(np.float) == np.float
Out[6]: True"><pre class="notranslate"><code class="notranslate">In [6]: np.dtype(np.float) == np.float
Out[6]: True
</code></pre></div>