title: Pearsonr: TypeError: No loop matching the specified signature and casting was found for ufunc add
body: <p>I have a timeseries Pandas dataframe called "df". It has one column and the following shape: (2000, 1). The head of the dataframe, below, shows its structure:</p>
  
  <pre><code>            Weight
  Date    
  2004-06-01  1.9219
  2004-06-02  1.8438
  2004-06-03  1.8672
  2004-06-04  1.7422
  2004-06-07  1.8203
  </code></pre>
  
  <p><strong>Goal</strong></p>
  
  <p>I am trying to use a "for-loop" to calculate the correlation between the percentage change of the "Weight" variable over various timeframes or timelags. This is being done to evaluate the impact of holding livestock over time periods of various lengths.</p>
  
  <p>The loop can be found below:</p>
  
  <pre><code>from scipy.stats.stats import pearsonr
  
  # Loop for producing combinations of different timelags and holddays 
  # and calculating the pearsonr correlation and p-value of each combination 
  
  for timelags in [1, 5, 10, 25, 60, 120, 250]:
      for holddays in [1, 5, 10, 25, 60, 120, 250]:
          weight_change_lagged = df.pct_change(periods=timelags)
          weight_change_future = df.shift(-holddays).pct_change(periods=holddays)
  
          if (timelags &gt;= holddays):
              indepSet=range(0, weight_change_lagged.shape[0], holddays)
          else:
              indepSet=range(0, weight_change_lagged.shape[0], timelags)
  
          weight_change_lagged = weight_change_lagged.iloc[indepSet]
          weight_change_future = weight_change_future.iloc[indepSet]
  
          not_na = (weight_change_lagged.notna() &amp; weight_change_future.notna()).values
  
          (correlation, p-value)=pearsonr(weight_change_lagged[not_na], weight_change_future[not_na])
          print('%4i %4i %7.4f %7.4f' % (timelags, holddays, correlation, p-value))
  </code></pre>
  
  <p>The loop executes well, however, it fails when it comes to calculating the pearsonr correlation and p-value, i.e at this section:</p>
  
  <pre><code>(correlation, p-value)=pearsonr(weight_change_lagged[not_na], weight_change_future[not_na])
  </code></pre>
  
  <p>It generates this error:</p>
  
  <blockquote>
    <p>TypeError: no loop matching the specified signature and casting was
    found for ufunc add</p>
  </blockquote>
  
  <p>Does anyone have any clues on how to fix my problem? I <a href="https://www.google.com/search?q=typeerror:%20no%20loop%20matching%20the%20specified%20signature%20and%20casting%20was%20found%20for%20ufunc%20add%20site:stackoverflow.com&amp;sxsrf=ALeKk01c0XWlDy-oYlFhYwpcv6dSrc3LzA:1589975911095&amp;sa=X&amp;ved=2ahUKEwiZ_IbrscLpAhXkShUIHYUYAUMQrQIoBDAAegQIBRAN&amp;biw=1366&amp;bih=576" rel="noreferrer">looked through the forums</a> and found no answers that fit my exact requirements.</p>