<p dir="auto">I have found that <code class="notranslate">lstsq</code> is sometimes throwing an exception; this is causing major problems because it's used in things like sklearn's <code class="notranslate">LinearRegression</code> class.  I've included below a particular very simplified repro, but there appear to be an unpredictable but somewhat widespread set of circumstances that can trigger this bug.</p>
<h4 dir="auto">Reproducing code example:</h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import matplotlib.pyplot as plt
import numpy as np
from scipy.linalg import lstsq

n = 9 # doesn't repro for n&lt;=8

# Generate covariates and outcomes
X = np.arange(n).reshape(-1,1)
Y = X

# plot anything with dashed lines (doesn't repro with default line style!)
plt.plot([1,2], [3,4], '--')

lstsq(X,Y)"><pre class="notranslate"><code class="notranslate">import matplotlib.pyplot as plt
import numpy as np
from scipy.linalg import lstsq

n = 9 # doesn't repro for n&lt;=8

# Generate covariates and outcomes
X = np.arange(n).reshape(-1,1)
Y = X

# plot anything with dashed lines (doesn't repro with default line style!)
plt.plot([1,2], [3,4], '--')

lstsq(X,Y)
</code></pre></div>
<h4 dir="auto">Error message</h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
 in 
     12 plt.plot([1,2], [3,4], '--')
     13 
---&gt; 14 lstsq(X,Y)

c:\Users\kebatt\source\repos\ProjectAliceCore\automl_venv\lib\site-packages\scipy\linalg\basic.py in lstsq(a, b, cond, overwrite_a, overwrite_b, check_finite, lapack_driver)
   1222         if info &lt; 0:
   1223             raise ValueError('illegal value in %d-th argument of internal %s'
-&gt; 1224                              % (-info, lapack_driver))
   1225         resids = np.asarray([], dtype=x.dtype)
   1226         if m &gt; n:

ValueError: illegal value in 4-th argument of internal None"><pre class="notranslate"><code class="notranslate">---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
 in 
     12 plt.plot([1,2], [3,4], '--')
     13 
---&gt; 14 lstsq(X,Y)

c:\Users\kebatt\source\repos\ProjectAliceCore\automl_venv\lib\site-packages\scipy\linalg\basic.py in lstsq(a, b, cond, overwrite_a, overwrite_b, check_finite, lapack_driver)
   1222         if info &lt; 0:
   1223             raise ValueError('illegal value in %d-th argument of internal %s'
-&gt; 1224                              % (-info, lapack_driver))
   1225         resids = np.asarray([], dtype=x.dtype)
   1226         if m &gt; n:

ValueError: illegal value in 4-th argument of internal None
</code></pre></div>
<h4 dir="auto">Scipy/Numpy/Python version information:</h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="1.5.2 1.19.2 sys.version_info(major=3, minor=6, micro=6, releaselevel='final', serial=0)"><pre class="notranslate"><code class="notranslate">1.5.2 1.19.2 sys.version_info(major=3, minor=6, micro=6, releaselevel='final', serial=0)
</code></pre></div>
<p dir="auto">I am running Windows 10 version 2004, so I assume this is at least somewhat related to <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="650672204" data-permission-text="Title is private" data-url="https://github.com/numpy/numpy/issues/16744" data-hovercard-type="issue" data-hovercard-url="/numpy/numpy/issues/16744/hovercard" href="https://github.com/numpy/numpy/issues/16744">numpy/numpy#16744</a>, <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="682444304" data-permission-text="Title is private" data-url="https://github.com/scipy/scipy/issues/12747" data-hovercard-type="issue" data-hovercard-url="/scipy/scipy/issues/12747/hovercard" href="https://github.com/scipy/scipy/issues/12747">#12747</a>, etc., but the manifestation is different.</p>
<p dir="auto">I have found that <code class="notranslate">lstsq</code> is sometimes unexpectedly throwing an exception; this is causing major problems because it's used in things like sklearn's <code class="notranslate">LinearRegression</code> class.  I've included below a particular very simplified repro, but there appear to be an unpredictable but somewhat widespread set of circumstances that can trigger this bug.</p>
<h4 dir="auto">Reproducing code example:</h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import matplotlib.pyplot as plt
import numpy as np
from scipy.linalg import lstsq

n = 9 # doesn't repro for n&lt;=8

# Generate covariates and outcomes
X = np.arange(n).reshape(-1,1)
Y = X

# plot anything with dashed lines (doesn't repro with default line style!)
plt.plot([1,2], [3,4], '--')

lstsq(X,Y)"><pre class="notranslate"><code class="notranslate">import matplotlib.pyplot as plt
import numpy as np
from scipy.linalg import lstsq

n = 9 # doesn't repro for n&lt;=8

# Generate covariates and outcomes
X = np.arange(n).reshape(-1,1)
Y = X

# plot anything with dashed lines (doesn't repro with default line style!)
plt.plot([1,2], [3,4], '--')

lstsq(X,Y)
</code></pre></div>
<h4 dir="auto">Error message</h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
 in 
     12 plt.plot([1,2], [3,4], '--')
     13 
---&gt; 14 lstsq(X,Y)

c:\Users\kebatt\source\repos\ProjectAliceCore\automl_venv\lib\site-packages\scipy\linalg\basic.py in lstsq(a, b, cond, overwrite_a, overwrite_b, check_finite, lapack_driver)
   1222         if info &lt; 0:
   1223             raise ValueError('illegal value in %d-th argument of internal %s'
-&gt; 1224                              % (-info, lapack_driver))
   1225         resids = np.asarray([], dtype=x.dtype)
   1226         if m &gt; n:

ValueError: illegal value in 4-th argument of internal None"><pre class="notranslate"><code class="notranslate">---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
 in 
     12 plt.plot([1,2], [3,4], '--')
     13 
---&gt; 14 lstsq(X,Y)

c:\Users\kebatt\source\repos\ProjectAliceCore\automl_venv\lib\site-packages\scipy\linalg\basic.py in lstsq(a, b, cond, overwrite_a, overwrite_b, check_finite, lapack_driver)
   1222         if info &lt; 0:
   1223             raise ValueError('illegal value in %d-th argument of internal %s'
-&gt; 1224                              % (-info, lapack_driver))
   1225         resids = np.asarray([], dtype=x.dtype)
   1226         if m &gt; n:

ValueError: illegal value in 4-th argument of internal None
</code></pre></div>
<h4 dir="auto">Scipy/Numpy/Python version information:</h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="1.5.2 1.19.2 sys.version_info(major=3, minor=6, micro=6, releaselevel='final', serial=0)"><pre class="notranslate"><code class="notranslate">1.5.2 1.19.2 sys.version_info(major=3, minor=6, micro=6, releaselevel='final', serial=0)
</code></pre></div>
<p dir="auto">I am running Windows 10 version 2004, so I assume this is at least somewhat related to <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="650672204" data-permission-text="Title is private" data-url="https://github.com/numpy/numpy/issues/16744" data-hovercard-type="issue" data-hovercard-url="/numpy/numpy/issues/16744/hovercard" href="https://github.com/numpy/numpy/issues/16744">numpy/numpy#16744</a>, <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="682444304" data-permission-text="Title is private" data-url="https://github.com/scipy/scipy/issues/12747" data-hovercard-type="issue" data-hovercard-url="/scipy/scipy/issues/12747/hovercard" href="https://github.com/scipy/scipy/issues/12747">#12747</a>, etc., but the manifestation is different.</p>