title: Passing pandas read_csv call into another function with its named arguments
body: <p>Since functions are <a href="http://en.wikipedia.org/wiki/First-class_function" rel="nofollow noreferrer">first-class citizens</a> in Python I should be able to refactor this:</p>
  
  <pre class="lang-python prettyprint-override"><code>def get_events():
      csv_path = os.path.join(INPUT_CSV_PATH, DATA_NAME + '.csv')
      print(f'Starting reading events at {datetime.now()}')
      start_time = datetime.now()
      events = pd.read_csv(csv_path, dtype=DTYPES)
      end_time = datetime.now()
      print(f'Finished reading events at {end_time} ({end_time - start_time})')
      return events
  </code></pre>
  
  <p>To something like this:</p>
  
  <pre class="lang-python prettyprint-override"><code>def get_events():
      csv_path = os.path.join(INPUT_CSV_PATH, DATA_NAME + '.csv')
      events = _time_function_call('reading events', pd.read_csv, {'filepath_or_buffer': csv_path, 'dtype': DTYPES})
      return events
  
  def _time_function_call(message, func, *kwargs):
      print(f'Starting {message} at {datetime.now()}')
      start_time = datetime.now()
      result = func(*kwargs)
      end_time = datetime.now()
      print(f'Finished {message} at {end_time} ({end_time - start_time})')
      return result
  </code></pre>
  
  <p>I.e. pass the pandas <a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html" rel="nofollow noreferrer">read_csv</a> function and its named arguments into a helper function. (N.B. I wasn't sure how to pass in the named arguments when passing a function around, <a href="https://stackoverflow.com/a/32717920/575530">this answer</a> helped.)</p>
  
  <p>But after refactoring I get the following error: </p>
  
  <blockquote>
    <p>ValueError: Invalid file path or buffer object type: &lt;class 'dict'&gt;</p>
  </blockquote>
  
  <p>What am I missing about how to pass functions and their named parameters into another Python function for evaluation?</p>