pydata/pandas — pull request #3145 by jreback (2013-03-23 15:58:53+00:00)
Title: PERF: GH2121 groupby transform

closes #2121

Two items were causing slowness

1) using apply for each group (which in this case is equivalent to directly calling
the function on the group). the function that is testing is ``fillna`` which we have defined as a function of a data frame so its ok here to use the direct function call

I create a slow_path/fast_path with the first group determining the path, not sure this is super robust, but it is a significant source of slowness

2) at the end of the groupby the concetated object has a reindex_like, this is way slow, replacing by sort_index is much faster (this is a multi-index), again not of the robustness, but all tests pass

This is a comparision of the bench/bench_transform.py (supplied in #2121)

The apply_by_group DOES include the sort_index (which is necessary for correctness)

```
In [2]: %timeit apply_by_group(grouped, f_fillna)
1 loops, best of 3: 2.11 s per loop

In [3]: %timeit grouped.transform(f_fillna)
1 loops, best of 3: 2.14 s per loop
```