<h3 dir="auto">Describe the issue:</h3>
<p dir="auto">Currently <code class="notranslate">np.array([np.nan], dtype=np.int64)</code> raises an error, however <code class="notranslate">np.array([np.nan]).astype(np.int64)</code> is undefined behavior that only issues a warning. Would it be worth promoting this to an error to stay consistent with <code class="notranslate">np.array</code> behavior?</p>
<h3 dir="auto">Reproduce the 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

np.array([np.nan]).astype(np.int64) # Works while issuing 'invalid value' warning

np.array([np.nan], dtype=np.int64) # Raises 'ValueError: cannot convert float NaN to integer'"><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">np</span>.<span class="pl-en">array</span>([<span class="pl-s1">np</span>.<span class="pl-s1">nan</span>]).<span class="pl-en">astype</span>(<span class="pl-s1">np</span>.<span class="pl-s1">int64</span>) <span class="pl-c"># Works while issuing 'invalid value' warning</span>

<span class="pl-s1">np</span>.<span class="pl-en">array</span>([<span class="pl-s1">np</span>.<span class="pl-s1">nan</span>], <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">np</span>.<span class="pl-s1">int64</span>) <span class="pl-c"># Raises 'ValueError: cannot convert float NaN to integer'</span></pre></div>
<h3 dir="auto">Error message:</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">NumPy/Python version information:</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="1.24.0.dev0+578.g918065167 3.9.12 (main, Jun  1 2022, 11:38:51) 
[GCC 7.5.0]"><pre class="notranslate"><code class="notranslate">1.24.0.dev0+578.g918065167 3.9.12 (main, Jun  1 2022, 11:38:51) 
[GCC 7.5.0]
</code></pre></div>
<p dir="auto">I tried to install recent NumPy (1.14.4), forced by SciPy :(<br>
It works in local env but not in Docker running Alpine.</p>
<p dir="auto">Minimal Docker file that reproduces the problem:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="FROM python:3.6.5-alpine
RUN apk add --no-cache build-base
RUN pip install numpy==1.14.4"><pre class="notranslate"><code class="notranslate">FROM python:3.6.5-alpine
RUN apk add --no-cache build-base
RUN pip install numpy==1.14.4
</code></pre></div>
<p dir="auto">By using 1.14.3 it all works.</p>