Skip to content

Commit

Permalink
BUG: use map_infer in applymap, speed boost and fix #465
Browse files Browse the repository at this point in the history
  • Loading branch information
wesm committed Dec 12, 2011
1 parent 9c20734 commit 6aa80f9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
2 changes: 2 additions & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ pandas 0.6.1
- Implement new SparseList and SparseArray data structures. SparseSeries now
derives from SparseArray (GH #463)
- max_columns / max_rows options in set_printoptions (PR #453)
- Implement Series.rank and DataFrame.rank, fast versions of
scipy.stats.rankdata (GH #428)

**Improvements to existing features**

Expand Down
12 changes: 1 addition & 11 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2410,17 +2410,7 @@ def applymap(self, func):
-------
applied : DataFrame
"""
npfunc = np.frompyfunc(func, 1, 1)

def f(x):
result = npfunc(x)
try:
result = result.astype(x.dtype)
except Exception:
pass
return result

return self.apply(f)
return self.apply(lambda x: lib.map_infer(x, func))

#----------------------------------------------------------------------
# Merging / joining methods
Expand Down
4 changes: 4 additions & 0 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2923,6 +2923,10 @@ def test_applymap(self):
assert_frame_equal(applied, self.frame * 2)
result = self.frame.applymap(type)

# GH #465, function returning tuples
result = self.frame.applymap(lambda x: (x, x))
self.assert_(isinstance(result['A'][0], tuple))

def test_filter(self):
# items

Expand Down

0 comments on commit 6aa80f9

Please sign in to comment.