Skip to content

Commit 75026f2

Browse files
committed
ENH: int64 type handling fix, tweaks, GH #309
1 parent 74f5d6d commit 75026f2

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

RELEASE.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ pandas 0.5.1
5959
micro-performance tweaks (GH #360)
6060
- Add `cov` instance methods to Series and DataFrame (GH #194, PR #362)
6161
62-
6362
**Improvements to existing features**
6463

6564
- Sped up `DataFrame.apply` performance in most cases
@@ -84,6 +83,10 @@ pandas 0.5.1
8483
motivated by PR #355
8584
- Cythonized `cache_readonly`, resulting in substantial micro-performance
8685
enhancements throughout the codebase (GH #361)
86+
- Special Cython matrix iterator for applying arbitrary reduction operations
87+
with 3-5x better performance than `np.apply_along_axis` (GH #309)
88+
- Add `raw` option to `DataFrame.apply` for getting better performance when
89+
the passed function only requires an ndarray (GH #309)
8790

8891
**Bug fixes**
8992

pandas/src/reduce.pyx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,21 @@ cdef class Reducer:
5454
arr = self.arr
5555
chunk = self.dummy
5656

57-
result = np.empty(self.nresults, dtype=self.arr.dtype)
58-
it = <flatiter> PyArray_IterNew(result)
59-
60-
test = self.f(self.chunk)
57+
test = self.f(chunk)
6158
try:
59+
assert(not isinstance(test, np.ndarray))
60+
if hasattr(test, 'dtype'):
61+
result = np.empty(self.nresults, dtype=test.dtype)
62+
else:
63+
result = np.empty(self.nresults, dtype='O')
6264
result[0] = test
6365
except Exception:
6466
raise ValueError('function does not reduce')
6567

68+
it = <flatiter> PyArray_IterNew(result)
69+
6670
dummy_buf = chunk.data
6771
chunk.data = arr.data
68-
6972
try:
7073
for i in range(self.nresults):
7174
PyArray_SETITEM(result, PyArray_ITER_DATA(it),
@@ -76,6 +79,9 @@ cdef class Reducer:
7679
# so we don't free the wrong memory
7780
chunk.data = dummy_buf
7881

82+
if result.dtype == np.object_:
83+
result = maybe_convert_objects(result)
84+
7985
return result
8086

8187
def reduce(arr, f, axis=0, dummy=None):

pandas/src/sandbox.pyx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ cdef class SeriesIterator:
1010

1111
def next(self):
1212
pass
13+
14+
def foo(object o):
15+
cdef int64_t bar = o
16+
return bar

0 commit comments

Comments
 (0)