title: Python "TypeError: 'Series' objects are mutable, thus they cannot be hashed" raised only when code is written in a funciton
body: <p>I'm writing a function that needs to use multiprocessing to make calculations on data stored in a pandas.DataFrame. The code looks something like this:</p>
  
  <pre><code>import pandas as pd
  from multiprocessing import Pool
  
  def foo(data_frame):
      #do stuff
  
  def bar(data_frame, n)
      pool = Pool(n)
      result = pool.map(foo, data_frame)
      pool.close()
      pool.join()
      return result
  
  data_frame = pd.DataFrame(&lt;data&gt;, columns=['a', 'b', 'c', 'd'])
  
  #because Pool.map() requires a list of arguments as the 2nd argument:
  df_aslist = [data_frame.iloc[i] for i in range(len(data_frame))]
  bar(data_frame=df_aslist, n=5)
  </code></pre>
  
  <p>When I run the code I get this error:</p>
  
  <pre><code>TypeError: 'Series' objects are mutable, thus they cannot be hashed
  </code></pre>
  
  <p>But if I were to write the code inside bar() outside the function like so:</p>
  
  <pre><code>data_frame = pd.DataFrame(&lt;data&gt;, columns=['a', 'b', 'c', 'd'])
  df_aslist = [data_frame.iloc[i] for i in range(len(data_frame))]
  pool = Pool(n)
  result = pool.map(foo, df_aslist)
  pool.close()
  pool.join()
  </code></pre>
  
  <p>The code runs without errors. My question is why? And also how can I fix the issue for when I write it in a function bar()?</p>
  
  <p>Thanks in advance!</p>
  
  <p><strong>Edit:</strong> I'll provide more details to give a better understanding of my example.
  The purpose of my program is to take pairs of lat-lon coordinates and calculate the distance and duration between them. The pairs of coordinates is what data_frame is containing, so it looks more like this:</p>
  
  <pre><code>data_frame = pd.DataFrame({
      'loc1lon' : loc1lon_list,
      'loc1lat' : loc1lat_list,
      'loc2lon' : loc2lon_list,
      'loc2lat' : loc2lat_list
  })
  </code></pre>
  
  <p>The distance is being calculated with libOSRM, the backend library that OSRM (Open Source Routing Machine) uses to make routing calculations. It is a C++ library, so I used Boost::Python to write a simple module that can use libOSRM (I named the module PyOSRM :P). I use it in my program like so:</p>
  
  <pre><code>import PyOSRM
  def foo(data):
      #foo is defined as a trick to allow multiprocessing to be used on boost::python funcitons. Would not work otherwise.
      return PyOSRM.calculate_loc_data(data)
  </code></pre>