pydata/pandas — pull request #6759 by dalejung (2014-04-01 15:56:46+00:00)
Title: PRF: Optimize 2d take operations.

Wanted to get eyes on this. The original axis=1 2d methods were optimized for Fortran. I changed it to be friendly to C order and transposed the array when F ordered.

These timings are for master. `cdf` is just the consolidated dataframe to switch from C to F.
```
In [3]:
%timeit a = df.take(indexes, axis=0)
10 loops, best of 3: 214 ms per loop

In [4]:
%timeit a = df.take(indexes, axis=1)
1 loops, best of 3: 978 ms per loop

In [8]:
%timeit cdf.take(indexes, axis=0)
1 loops, best of 3: 1.6 s per loop

In [9]:
%timeit cdf.take(indexes, axis=1)
1 loops, best of 3: 216 ms per loop
```
http://nbviewer.ipython.org/gist/dalejung/9914956/pandas%20perf_baseline.ipynb

The PR timings are:
```
In [23]:

%timeit cdf.take(indexes, axis=0)
1 loops, best of 3: 290 ms per loop
In [24]:

%timeit cdf.take(indexes, axis=1)
1 loops, best of 3: 222 ms per loop

In [23]:
%timeit cdf.take(indexes, axis=0)
1 loops, best of 3: 290 ms per loop

In [24]:
%timeit cdf.take(indexes, axis=1)
1 loops, best of 3: 222 ms per loop
```
http://nbviewer.ipython.org/gist/dalejung/9914956/pandas%20perf.ipynb

It's similar behavior to the shift perf update.

For a numpy baseline i wrote:
```python
# wrap np.take to reshape to C order
def quick_take(values, indexer, axis=0):
f_ordered = values.flags.f_contiguous
if f_ordered:
values = values.T
axis = values.ndim - axis - 1
res = values.take(indexes, axis)
if f_ordered:
res = res.T
return res

%timeit quick_take(df.values, indexes, axis=0)
1 loops, best of 3: 234 ms per loop

In [14]:
%timeit quick_take(df.values, indexes, axis=1)
1 loops, best of 3: 271 ms per loop
```

Which are similar timings.