<p dir="auto">My issue is taking a warning, while it is not logical.</p>
<h3 dir="auto">Reproducing code example:</h3>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import numpy as np
from scipy.stats import pearsonr, spearmanr
x = np.asarray([0.20411998265592482, 0.07918124604762482])
y = np.asarray([0.017448610113466535, 0.012129956392826626])
print(pearsonr(x,y))"><pre class="notranslate"><code class="notranslate">import numpy as np
from scipy.stats import pearsonr, spearmanr
x = np.asarray([0.20411998265592482, 0.07918124604762482])
y = np.asarray([0.017448610113466535, 0.012129956392826626])
print(pearsonr(x,y))
</code></pre></div>
<h3 dir="auto">Warning message:</h3>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="/usr/local/lib/python3.5/dist-packages/scipy/stats/stats.py:3020: RuntimeWarning: invalid value encountered in double_scalars
  prob = _betai(0.5*df, 0.5, df/(df+t_squared))"><pre class="notranslate"><code class="notranslate">/usr/local/lib/python3.5/dist-packages/scipy/stats/stats.py:3020: RuntimeWarning: invalid value encountered in double_scalars
  prob = _betai(0.5*df, 0.5, df/(df+t_squared))
</code></pre></div>
<h3 dir="auto">Output</h3>
<p dir="auto">Below + warning above.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="(0.9999999999999999, nan)"><pre class="notranslate"><code class="notranslate">(0.9999999999999999, nan)
</code></pre></div>
<h3 dir="auto">Expected Output</h3>
<p dir="auto">I expect getting no warning. in addition p-value must be 0 not nan!</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="(1.0, 0.0)"><pre class="notranslate"><code class="notranslate">(1.0, 0.0)
</code></pre></div>
<h3 dir="auto">Scipy/Numpy/Python version information:</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="1.1.0 1.14.5 sys.version_info(major=3, minor=5, micro=2, releaselevel='final', serial=0)"><pre class="notranslate"><code class="notranslate">1.1.0 1.14.5 sys.version_info(major=3, minor=5, micro=2, releaselevel='final', serial=0)
</code></pre></div>
<p dir="auto">Hi,</p>
<p dir="auto">This is an issue to mention that the implementation of pearsonr is not tolerant to overflows.</p>
<p dir="auto"></p><div class="Box Box--condensed my-2">
  <div class="Box-header f6">
    <p class="mb-0 text-bold">
      <a href="https://github.com/scipy/scipy/blob/b7865dd1b88db975e7ba51f3fde2e5982d561c8b/scipy/stats/stats.py#L3032">scipy/scipy/stats/stats.py</a>
    </p>
    <p class="mb-0 color-fg-muted">
         Line 3032
      in
      <a data-pjax="true" class="commit-tease-sha" href="/scipy/scipy/commit/b7865dd1b88db975e7ba51f3fde2e5982d561c8b">b7865dd</a>
    </p>
  </div>
  <div itemprop="text" class="Box-body p-0 blob-wrapper blob-wrapper-embedded data">
    <table class="highlight tab-size mb-0 js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">

        <tbody><tr class="border-0">
          <td id="L3032" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="3032"></td>
          <td id="LC3032" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-s1">r_den</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">sqrt</span>(<span class="pl-en">_sum_of_squares</span>(<span class="pl-s1">xm</span>) <span class="pl-c1">*</span> <span class="pl-en">_sum_of_squares</span>(<span class="pl-s1">ym</span>)) </td>
        </tr>
    </tbody></table>
  </div>
</div>
<p></p>
<p dir="auto">Pearsonr is stable by a multiplicative coefficient. When this coefficient is too high, the computation fails with an error message:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="scipy/stats/stats.py:3013: RuntimeWarning: overflow encountered in double_scalars
  r_den = np.sqrt(_sum_of_squares(xm) * _sum_of_squares(ym))"><pre class="notranslate"><code class="notranslate">scipy/stats/stats.py:3013: RuntimeWarning: overflow encountered in double_scalars
  r_den = np.sqrt(_sum_of_squares(xm) * _sum_of_squares(ym))
</code></pre></div>
<p dir="auto">The sum of squares product here is too high. Need to adapt the computation so that this partial computation is avoided.</p>
<p dir="auto">To reproduce (starting from the documentation example in master branch):</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import numpy as np
from scipy import stats

a = np.array([0, 0, 0, 1, 1, 1, 1])
b = np.arange(7)
pearson1 = stats.pearsonr(a, b)
a1 = a * 1e90
b1 = b * 1e90
pearson2 = stats.pearsonr(a1, b1)
print(pearson1 , pearson2)
assert(np.allclose(pearson1[0] , pearson2[0]))
assert(np.allclose(pearson1[1] , pearson2[1]))"><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-k">from</span> <span class="pl-s1">scipy</span> <span class="pl-k">import</span> <span class="pl-s1">stats</span>

<span class="pl-s1">a</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">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span class="pl-c1">1</span>])
<span class="pl-s1">b</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">arange</span>(<span class="pl-c1">7</span>)
<span class="pl-s1">pearson1</span> <span class="pl-c1">=</span> <span class="pl-s1">stats</span>.<span class="pl-en">pearsonr</span>(<span class="pl-s1">a</span>, <span class="pl-s1">b</span>)
<span class="pl-s1">a1</span> <span class="pl-c1">=</span> <span class="pl-s1">a</span> <span class="pl-c1">*</span> <span class="pl-c1">1e90</span>
<span class="pl-s1">b1</span> <span class="pl-c1">=</span> <span class="pl-s1">b</span> <span class="pl-c1">*</span> <span class="pl-c1">1e90</span>
<span class="pl-s1">pearson2</span> <span class="pl-c1">=</span> <span class="pl-s1">stats</span>.<span class="pl-en">pearsonr</span>(<span class="pl-s1">a1</span>, <span class="pl-s1">b1</span>)
<span class="pl-en">print</span>(<span class="pl-s1">pearson1</span> , <span class="pl-s1">pearson2</span>)
<span class="pl-k">assert</span>(<span class="pl-s1">np</span>.<span class="pl-en">allclose</span>(<span class="pl-s1">pearson1</span>[<span class="pl-c1">0</span>] , <span class="pl-s1">pearson2</span>[<span class="pl-c1">0</span>]))
<span class="pl-k">assert</span>(<span class="pl-s1">np</span>.<span class="pl-en">allclose</span>(<span class="pl-s1">pearson1</span>[<span class="pl-c1">1</span>] , <span class="pl-s1">pearson2</span>[<span class="pl-c1">1</span>]))</pre></div>
<p dir="auto">Versions :</p>
<p dir="auto">output of 'import sys, scipy, numpy;  print(scipy.<strong>version</strong>, numpy.<strong>version</strong>, sys.version_info)'</p>
<p dir="auto">1.1.0 1.14.5 sys.version_info(major=3, minor=6, micro=5, releaselevel='final', serial=0)</p>
<p dir="auto">Also performed a lookup to see if a similar issue already exists.</p>