title: improve pandas and dask aggregate custom function speed
body: <p>For pandas/dask aggregate, using the built in function. It is indeed very fast. For example, my initial aggregate function works very efficiently. This aggregate function works very smooth</p>
  <pre><code>{&quot;volume&quot;:[&quot;sum&quot;],&quot;high&quot;:[&quot;max&quot;],&quot;low&quot;:[&quot;min&quot;]}
  </code></pre>
  <p>However, I also need the first and last aggregate</p>
  <pre><code>def first(rows):
      return rows[0]
  def last(rows):
      return rows[-1]
  
  {&quot;volume&quot;:[&quot;sum&quot;],&quot;open&quot;:[first],&quot;close&quot;:[last],&quot;high&quot;:[&quot;max&quot;],&quot;low&quot;:[&quot;min&quot;]}
  </code></pre>
  <p>Such aggregate becomes 100 times slower... Is it possible to use some tricks to improve its performance? Like using cypthon, numba etc.?</p>
  <p><strong>Edit</strong>: ok, so pandas has such aggregate function, I'm actually running it in dask with this line:</p>
  <pre><code>        final_df_tmp =  df_tx_counts_input.map_overlap(
              lambda x: x.groupby(id_col_name)[data_cols_tmp].rolling(f&quot;{rolling_window_now}ns&quot;).agg(agg_operations).sort_index(level=1), 
              pd.Timedelta(f&quot;{rolling_window_now}ns&quot;), 
              0)#.reset_index()
  </code></pre>
  <p>If I used the custom built in :</p>
  <pre><code>    grand_agg_instruction[rolling_window_now]={&quot;volume&quot;:[&quot;sum&quot;],&quot;open&quot;:[&quot;first&quot;],&quot;close&quot;:[&quot;last&quot;],&quot;high&quot;:[&quot;max&quot;],&quot;low&quot;:[&quot;min&quot;]}
  </code></pre>
  <p>Error says:</p>
  <pre><code>AttributeError(&quot;'first' is not a valid function for 'RollingGroupby' object&quot;)
  </code></pre>