title: Change default arguments of function in python
body: <p>I have a function that converts a numpy array to a array containing True or False based on a condition then groups the True or False entries that are adjacent to one another and calculates the length of each group. This is to determine the length of dry spells or wet spells in a given month of precipitation data.</p>
  
  <p>This is the function:</p>
  
  <pre><code>import itertools
  def spell(X, kind='wet', how='mean', threshold=0.5): 
  
      if kind=='wet':
          condition = X&gt;threshold
      else:
          condition = X&lt;=threshold
  
      length = [sum(1 if x==True else nan for x in group) for key,group in itertools.groupby(condition) if key]
  
      if not length: 
          res = 0
      elif how=='mean': 
          res = np.mean(length)
      else:
          res = np.max(length)
  
      return res
  </code></pre>
  
  <p>So basically there is the option to determine the mean length or maximum length of wet or dry spells given a numpy array of precipitation data with the default parameters set to the mean length of wet spells.</p>
  
  <p>I use this function with pandas to apply it to each month of a historical record:</p>
  
  <pre><code>#Create example dataframe
  np.random.seed(1324)
  idx = pd.DatetimeIndex(start='1960-01-01', periods=100, freq='d')
  values = np.random.random(100)
  df = pd.DataFrame(values, index=idx)
  
  #Apply function
  df.resample('M', how=spell)
  </code></pre>
  
  <p>and what I get is:</p>
  
  <pre><code>0
  1960-01-31  1.555556
  1960-02-29  1.500000
  1960-03-31  1.777778
  1960-04-30  6.000000
  </code></pre>
  
  <p>Which is perfect, however I want to be able to change the default values of this function somewhat on the fly so that I can use it's other options with df.resample(). I've looked into <code>functools.partial()</code> however this is only a solution for cases where the input arguments are explicitly set ie. <code>spell(kind='dry', how='max', threshold=0.7)</code>. Is there a way to change the default arguments of the function in a way they will not need to be explicitly set afterwords so that I can used it with <code>df.resample()</code>?</p>