title: Fun with Pandas `rolling_apply` and TypeError
body: <p>I'm really struggling with the Pandas <code>rolling_apply function</code>. I'm trying to apply a filter to some time series data like below and make a new series for outliers. I want the value to return <code>True</code> when the value is an outlier. </p>
  
  <pre><code>ts = pd.Series(np.random.randn(1000), index=pd.date_range('1/1/2000', periods=1000))
  
  window, alpha, gamma = 60, .05, .03
  
  def trim_moments(arr, alpha):
      np.sort(arr)
      n = len(arr)
      k = int(round(n*float(alpha))/2)
      return np.mean(arr[k+1:n-k]), np.std(arr[k+1:n-k])
  
  # First function that tests whether criteria is met.
  def bg_test(arr,alpha,gamma):
      local_mean, local_std = trim_moments(arr, alpha)
      return np.abs(arr - local_mean) &lt; 3 * local_std + gamma
  </code></pre>
  
  <p>This is the function that I run</p>
  
  <pre><code>outliers = pd.rolling_apply(ts, window, bg_test, args=(alpha,gamma))
  </code></pre>
  
  <p>Returns the error:</p>
  
  <pre><code>TypeError: only length-1 arrays can be converted to Python scalars
  </code></pre>
  
  <p>My troubleshooting indicates that the problem lies in the boolean return statement. I keep getting the similar error when I simplify the function and use <code>np.mean/std</code> rather than my own functions. It seems like previous issues with <code>TypeError</code> were due to performing non-vectorized operations on Numpy Arrays but this doesn't seem to be the issue here. </p>
  
  <p>What am I doing wrong here?</p>