<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; df = pd.DataFrame([[1, 2], [3, 4]], columns=['a', 'b'])
&gt;&gt;&gt; ar = np.array(0)
&gt;&gt;&gt; df.iloc[ar]
Traceback (most recent call last):
  ...
  ...
  File &quot;/home/float2/Documents/Python/Pandas/pandas/pandas/core/indexes/base.py&quot;, line 529, in _shallow_copy_with_infer
    if not len(values) and 'dtype' not in kwargs:
TypeError: object of type 'numpy.int64' has no len()
"><pre class="notranslate"><span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">df</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>([[<span class="pl-c1">1</span>, <span class="pl-c1">2</span>], [<span class="pl-c1">3</span>, <span class="pl-c1">4</span>]], <span class="pl-s1">columns</span><span class="pl-c1">=</span>[<span class="pl-s">'a'</span>, <span class="pl-s">'b'</span>])
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">ar</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">array</span>(<span class="pl-c1">0</span>)
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">df</span>.<span class="pl-s1">iloc</span>[<span class="pl-s1">ar</span>]
<span class="pl-v">Traceback</span> (<span class="pl-s1">most</span> <span class="pl-s1">recent</span> <span class="pl-s1">call</span> <span class="pl-s1">last</span>):
  ...
  ...
  <span class="pl-v">File</span> <span class="pl-s">"/home/float2/Documents/Python/Pandas/pandas/pandas/core/indexes/base.py"</span>, <span class="pl-s1">line</span> <span class="pl-c1">529</span>, <span class="pl-s1">in</span> <span class="pl-s1">_shallow_copy_with_infer</span>
    <span class="pl-k">if</span> <span class="pl-c1">not</span> <span class="pl-en">len</span>(<span class="pl-s1">values</span>) <span class="pl-c1">and</span> <span class="pl-s">'dtype'</span> <span class="pl-c1">not</span> <span class="pl-c1">in</span> <span class="pl-s1">kwargs</span>:
<span class="pl-v">TypeError</span>: <span class="pl-s1">object</span> <span class="pl-s1">of</span> <span class="pl-s1">type</span> <span class="pl-s">'numpy.int64'</span> <span class="pl-s1">has</span> <span class="pl-s1">no</span> <span class="pl-en">len</span>()</pre></div>
<p dir="auto">A 0-d array passes <a href="https://github.com/pandas-dev/pandas/blob/1a23779f09abc6ebf908d66ee88b973b767e2e3c/pandas/core/indexing.py#L2090">this</a> check cause it is an Iterable. But later, when <strong>len()</strong> is called on, TypeError is raised.<br>
It would be nice to implement <a href="https://www.python.org/dev/peps/pep-0357/" rel="nofollow">PEP 357</a> to prevent this error.<br>
The matter has been raised at PyTorch project. <a href="https://github.com/pytorch/pytorch/pull/9237" data-hovercard-type="pull_request" data-hovercard-url="/pytorch/pytorch/pull/9237/hovercard">#9237</a></p>
<h4 dir="auto">Code Sample, a copy-pastable example if possible</h4>
<p dir="auto">The code below works correctly.</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="df=pd.DataFrame([[1,2],[3,4]])
df.iloc[np.array([0])]"><pre class="notranslate"><span class="pl-s1">df</span><span class="pl-c1">=</span><span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>([[<span class="pl-c1">1</span>,<span class="pl-c1">2</span>],[<span class="pl-c1">3</span>,<span class="pl-c1">4</span>]])
<span class="pl-s1">df</span>.<span class="pl-s1">iloc</span>[<span class="pl-s1">np</span>.<span class="pl-en">array</span>([<span class="pl-c1">0</span>])]</pre></div>
<p dir="auto">But the code below raises an error.</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="df.iloc[np.array(0)]"><pre class="notranslate"><span class="pl-s1">df</span>.<span class="pl-s1">iloc</span>[<span class="pl-s1">np</span>.<span class="pl-en">array</span>(<span class="pl-c1">0</span>)]</pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="TypeError: object of type 'numpy.int64' has no len()"><pre class="notranslate"><code class="notranslate">TypeError: object of type 'numpy.int64' has no len()
</code></pre></div>