Skip to content

Commit

Permalink
BUG: DataFrame.apply function returning list resulted in unexpected S…
Browse files Browse the repository at this point in the history
…eries return value, GH #432
  • Loading branch information
wesm committed Dec 2, 2011
1 parent 8a2520b commit c6d05e5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@ pandas 0.6.1
axis (GH #423)
- Fix Yahoo! Finance API usage in pandas.io.data (GH #419, PR #427)
- Fix upstream bug causing failure in Series.align with empty Series (GH #434)
- Function passed to DataFrame.apply can return a list, as long as it's the
right length. Regression from 0.4 (GH #432)

Thanks
------
- Ralph Bean
- Joon Ro
- Wouter Overmeire
- Chris Uga

pandas 0.6.0
============
Expand Down
2 changes: 2 additions & 0 deletions pandas/src/reduce.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ cdef class Reducer:
def _get_result_array(self, object res):
try:
assert(not isinstance(res, np.ndarray))
assert(not (isinstance(res, list) and len(res) == len(self.dummy)))

result = np.empty(self.nresults, dtype='O')
# if hasattr(res, 'dtype'):
# result = np.empty(self.nresults, dtype=res.dtype)
Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2795,6 +2795,17 @@ def subtract_and_divide(x, sub, divide=1):
exp = self.frame.apply(lambda x: (x - 2.) / 2.)
assert_frame_equal(res, exp)

def test_apply_yield_list(self):
result = self.frame.apply(list)
assert_frame_equal(result, self.frame)

def test_apply_reduce_Series(self):
self.frame.ix[::2, 'A'] = np.nan
result = self.frame.apply(np.mean, axis=1)
expected = self.frame.mean(1)
assert_series_equal(result, expected)


def test_applymap(self):
applied = self.frame.applymap(lambda x: x * 2)
assert_frame_equal(applied, self.frame * 2)
Expand Down

0 comments on commit c6d05e5

Please sign in to comment.