title: Patching a method without changing how the method works?
body: <p>I'm trying to test that a pandas method gets called with some values. </p>
  
  <p>However, just by applying a @patch decorator causes the patched method to throw a <code>ValueError</code> within pandas, when the actual method does not. I'm just trying to test that <code>Stock.calc_sma</code> is calling the underlying <code>pandas.rolling_mean</code> function. </p>
  
  <p>I'm under the assumption that the <code>@patch</code> decorator basically adds some "magic" methods to the thing I'm patching that allow me to check if the function was called. If this is the case, why doesn't the <code>pandas.rolling_mean</code> function behave the same whether it's patched vs. not patched?</p>
  
  <p>app/models.py</p>
  
  <pre><code>import pandas as pd
  class Stock:  # i've excluded a bunch of class methods, including the one that sets self.data, which is a DataFrame of stock prices.
      def calc_sma(self, num_days)
          if self.data.shape[0] &gt; num_days:  # Stock.data holds a DataFrame of stock prices
                  column_title = 'sma' + str(num_days)
                  self.data[column_title] = pd.rolling_mean(self.data['Adj Close'], num_days)
  </code></pre>
  
  <p>app/tests/TestStockModel.py</p>
  
  <pre><code>def setUp(self):
      self.stock = MagicMock(Stock)
      self.stock.ticker = "AAPL"
      self.stock.data = DataFrame(aapl_test_data.data)
  
  @patch('app.models.pd.rolling_mean')
  def test_calc_sma(self, patched_rolling_mean):
      Stock.calc_sma(self.stock, 3)
      assert(isinstance(self.stock.data['sma3'], Series))
      patched_rolling_mean.assert_any_call()
  </code></pre>
  
  <h2>ERROR: test_calc_sma (TestStockModel.TestStockModel)</h2>
  
  <pre><code>Traceback (most recent call last):
    File "/Users/grant/Code/python/chartflux/env/lib/python2.7/site-packages/mock.py", line 1201, in patched
      return func(*args, **keywargs)
    File "/Users/grant/Code/python/chartflux/app/tests/TestStockModel.py", line 26, in test_calc_sma
      Stock.calc_sma(self.stock, 3)
    File "/Users/grant/Code/python/chartflux/app/models.py", line 27, in calc_sma
      self.data[column_title] = pd.rolling_mean(self.data['Adj Close'], num_days)
    File "/Users/grant/Code/python/chartflux/env/lib/python2.7/site-packages/pandas/core/frame.py", line 1887, in __setitem__
      self._set_item(key, value)
    File "/Users/grant/Code/python/chartflux/env/lib/python2.7/site-packages/pandas/core/frame.py", line 1967, in _set_item
      value = self._sanitize_column(key, value)
    File "/Users/grant/Code/python/chartflux/env/lib/python2.7/site-packages/pandas/core/frame.py", line 2017, in _sanitize_column
      raise ValueError('Length of values does not match length of '
  ValueError: Length of values does not match length of index
  </code></pre>