<h3 dir="auto">Describe your issue.</h3>
<p dir="auto">Can't run <code class="notranslate">import scipy.stats</code> with numpy nightly</p>
<h3 dir="auto">Reproducing Code Example</h3>
<div class="highlight highlight-text-shell-session notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="(.311venv) marcogorelli@DESKTOP-U8OKFP3:~/pandas-dev$ pip install -U numpy
Collecting numpy
  Using cached numpy-1.24.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (17.3 MB)
Installing collected packages: numpy
Successfully installed numpy-1.24.1
(.311venv) marcogorelli@DESKTOP-U8OKFP3:~/pandas-dev$ python -c 'import scipy.stats'
(.311venv) marcogorelli@DESKTOP-U8OKFP3:~/pandas-dev$ pip uninstall numpy -y
Found existing installation: numpy 1.24.1
Uninstalling numpy-1.24.1:
  Successfully uninstalled numpy-1.24.1
(.311venv) marcogorelli@DESKTOP-U8OKFP3:~/pandas-dev$ pip install --pre --extra-index https://pypi.anaconda.org/scipy-wheels-nightly/simple numpy
Looking in indexes: https://pypi.org/simple, https://pypi.anaconda.org/scipy-wheels-nightly/simple
Collecting numpy
  Downloading https://pypi.anaconda.org/scipy-wheels-nightly/simple/numpy/1.25.0.dev0%2B405.g720cabc23/numpy-1.25.0.dev0%2B405.g720cabc23-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (17.3 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 17.3/17.3 MB 9.0 MB/s eta 0:00:00
Installing collected packages: numpy
Successfully installed numpy-1.25.0.dev0+405.g720cabc23
(.311venv) marcogorelli@DESKTOP-U8OKFP3:~/pandas-dev$ python -c 'import scipy.stats'
Traceback (most recent call last):
  File &quot;&lt;string&gt;&quot;, line 1, in &lt;module&gt;
  File &quot;/home/marcogorelli/pandas-dev/.311venv/lib/python3.11/site-packages/scipy/stats/__init__.py&quot;, line 484, in &lt;module&gt;
    from ._stats_py import *
  File &quot;/home/marcogorelli/pandas-dev/.311venv/lib/python3.11/site-packages/scipy/stats/_stats_py.py&quot;, line 46, in &lt;module&gt;
    from . import distributions
  File &quot;/home/marcogorelli/pandas-dev/.311venv/lib/python3.11/site-packages/scipy/stats/distributions.py&quot;, line 8, in &lt;module&gt;
    from ._distn_infrastructure import (rv_discrete, rv_continuous, rv_frozen)
  File &quot;/home/marcogorelli/pandas-dev/.311venv/lib/python3.11/site-packages/scipy/stats/_distn_infrastructure.py&quot;, line 25, in &lt;module&gt;
    from scipy import integrate
  File &quot;/home/marcogorelli/pandas-dev/.311venv/lib/python3.11/site-packages/scipy/integrate/__init__.py&quot;, line 91, in &lt;module&gt;
    from ._quadrature import *
  File &quot;/home/marcogorelli/pandas-dev/.311venv/lib/python3.11/site-packages/scipy/integrate/_quadrature.py&quot;, line 35, in &lt;module&gt;
    trapezoid = _copy_func(trapezoid)
                ^^^^^^^^^^^^^^^^^^^^^
  File &quot;/home/marcogorelli/pandas-dev/.311venv/lib/python3.11/site-packages/scipy/integrate/_quadrature.py&quot;, line 28, in _copy_func
    g = types.FunctionType(f.__code__, f.__globals__, name=f.__name__,
                           ^^^^^^^^^^
AttributeError: 'numpy._ArrayFunctionDispatcher' object has no attribute '__code__'. Did you mean: '__call__'?"><pre class="notranslate"><span class="pl-e">(.311venv) marcogorelli@DESKTOP-U8OKFP3:~/pandas-dev</span>$ <span class="pl-s1">pip install -U numpy</span>
<span class="pl-c1">Collecting numpy</span>
<span class="pl-c1">  Using cached numpy-1.24.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (17.3 MB)</span>
<span class="pl-c1">Installing collected packages: numpy</span>
<span class="pl-c1">Successfully installed numpy-1.24.1</span>
<span class="pl-e">(.311venv) marcogorelli@DESKTOP-U8OKFP3:~/pandas-dev</span>$ <span class="pl-s1">python -c <span class="pl-s"><span class="pl-pds">'</span>import scipy.stats<span class="pl-pds">'</span></span></span>
<span class="pl-e">(.311venv) marcogorelli@DESKTOP-U8OKFP3:~/pandas-dev</span>$ <span class="pl-s1">pip uninstall numpy -y</span>
<span class="pl-c1">Found existing installation: numpy 1.24.1</span>
<span class="pl-c1">Uninstalling numpy-1.24.1:</span>
<span class="pl-c1">  Successfully uninstalled numpy-1.24.1</span>
<span class="pl-e">(.311venv) marcogorelli@DESKTOP-U8OKFP3:~/pandas-dev</span>$ <span class="pl-s1">pip install --pre --extra-index https://pypi.anaconda.org/scipy-wheels-nightly/simple numpy</span>
<span class="pl-c1">Looking in indexes: https://pypi.org/simple, https://pypi.anaconda.org/scipy-wheels-nightly/simple</span>
<span class="pl-c1">Collecting numpy</span>
<span class="pl-c1">  Downloading https://pypi.anaconda.org/scipy-wheels-nightly/simple/numpy/1.25.0.dev0%2B405.g720cabc23/numpy-1.25.0.dev0%2B405.g720cabc23-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (17.3 MB)</span>
<span class="pl-c1">     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 17.3/17.3 MB 9.0 MB/s eta 0:00:00</span>
<span class="pl-c1">Installing collected packages: numpy</span>
<span class="pl-c1">Successfully installed numpy-1.25.0.dev0+405.g720cabc23</span>
<span class="pl-e">(.311venv) marcogorelli@DESKTOP-U8OKFP3:~/pandas-dev</span>$ <span class="pl-s1">python -c <span class="pl-s"><span class="pl-pds">'</span>import scipy.stats<span class="pl-pds">'</span></span></span>
<span class="pl-c1">Traceback (most recent call last):</span>
<span class="pl-c1">  File "&lt;string&gt;", line 1, in &lt;module&gt;</span>
<span class="pl-c1">  File "/home/marcogorelli/pandas-dev/.311venv/lib/python3.11/site-packages/scipy/stats/__init__.py", line 484, in &lt;module&gt;</span>
<span class="pl-c1">    from ._stats_py import *</span>
<span class="pl-c1">  File "/home/marcogorelli/pandas-dev/.311venv/lib/python3.11/site-packages/scipy/stats/_stats_py.py", line 46, in &lt;module&gt;</span>
<span class="pl-c1">    from . import distributions</span>
<span class="pl-c1">  File "/home/marcogorelli/pandas-dev/.311venv/lib/python3.11/site-packages/scipy/stats/distributions.py", line 8, in &lt;module&gt;</span>
<span class="pl-c1">    from ._distn_infrastructure import (rv_discrete, rv_continuous, rv_frozen)</span>
<span class="pl-c1">  File "/home/marcogorelli/pandas-dev/.311venv/lib/python3.11/site-packages/scipy/stats/_distn_infrastructure.py", line 25, in &lt;module&gt;</span>
<span class="pl-c1">    from scipy import integrate</span>
<span class="pl-c1">  File "/home/marcogorelli/pandas-dev/.311venv/lib/python3.11/site-packages/scipy/integrate/__init__.py", line 91, in &lt;module&gt;</span>
<span class="pl-c1">    from ._quadrature import *</span>
<span class="pl-c1">  File "/home/marcogorelli/pandas-dev/.311venv/lib/python3.11/site-packages/scipy/integrate/_quadrature.py", line 35, in &lt;module&gt;</span>
<span class="pl-c1">    trapezoid = _copy_func(trapezoid)</span>
<span class="pl-c1">                ^^^^^^^^^^^^^^^^^^^^^</span>
<span class="pl-c1">  File "/home/marcogorelli/pandas-dev/.311venv/lib/python3.11/site-packages/scipy/integrate/_quadrature.py", line 28, in _copy_func</span>
<span class="pl-c1">    g = types.FunctionType(f.__code__, f.__globals__, name=f.__name__,</span>
<span class="pl-c1">                           ^^^^^^^^^^</span>
<span class="pl-c1">AttributeError: 'numpy._ArrayFunctionDispatcher' object has no attribute '__code__'. Did you mean: '__call__'?</span></pre></div>
<h3 dir="auto">SciPy/NumPy/Python version information</h3>
<p dir="auto">1.11.0.dev0+1302.d5d04ef 1.25.0.dev0+405.g720cabc23 sys.version_info(major=3, minor=11, micro=1, releaselevel='final', serial=0)</p>
<p dir="auto">See for example <a href="https://github.com/scipy/scipy/actions/runs/3946141515/jobs/6753635939">this log</a>. Lots of this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="AttributeError: 'numpy._ArrayFunctionDispatcher' object has no attribute '__code__'"><pre class="notranslate"><code class="notranslate">AttributeError: 'numpy._ArrayFunctionDispatcher' object has no attribute '__code__'
</code></pre></div>
<p dir="auto">Should be due to <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1535012503" data-permission-text="Title is private" data-url="https://github.com/numpy/numpy/issues/23020" data-hovercard-type="pull_request" data-hovercard-url="/numpy/numpy/pull/23020/hovercard" href="https://github.com/numpy/numpy/pull/23020">numpy/numpy#23020</a> (Cc <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/seberg/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/seberg">@seberg</a>). There are two usages of  <code class="notranslate">__code__</code>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=" rg __code__
scipy/integrate/_quadrature.py
28:    g = types.FunctionType(f.__code__, f.__globals__, name=f.__name__,

scipy/interpolate/_rbf.py
193:               hasattr(self.function, '__code__'):
202:            argcount = val.__code__.co_argcount"><pre class="notranslate"><code class="notranslate"> rg __code__
scipy/integrate/_quadrature.py
28:    g = types.FunctionType(f.__code__, f.__globals__, name=f.__name__,

scipy/interpolate/_rbf.py
193:               hasattr(self.function, '__code__'):
202:            argcount = val.__code__.co_argcount
</code></pre></div>
<p dir="auto">Haven't checked yet what those do exactly, but either way this is a regression that's going to break already-released SciPy versions, so it should be fixed on the NumPy side.</p>