Skip to content

Commit 6aa80f9

Browse files
committed
BUG: use map_infer in applymap, speed boost and fix #465
1 parent 9c20734 commit 6aa80f9

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

RELEASE.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ pandas 0.6.1
4242
- Implement new SparseList and SparseArray data structures. SparseSeries now
4343
derives from SparseArray (GH #463)
4444
- max_columns / max_rows options in set_printoptions (PR #453)
45+
- Implement Series.rank and DataFrame.rank, fast versions of
46+
scipy.stats.rankdata (GH #428)
4547

4648
**Improvements to existing features**
4749

pandas/core/frame.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2410,17 +2410,7 @@ def applymap(self, func):
24102410
-------
24112411
applied : DataFrame
24122412
"""
2413-
npfunc = np.frompyfunc(func, 1, 1)
2414-
2415-
def f(x):
2416-
result = npfunc(x)
2417-
try:
2418-
result = result.astype(x.dtype)
2419-
except Exception:
2420-
pass
2421-
return result
2422-
2423-
return self.apply(f)
2413+
return self.apply(lambda x: lib.map_infer(x, func))
24242414

24252415
#----------------------------------------------------------------------
24262416
# Merging / joining methods

pandas/tests/test_frame.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2923,6 +2923,10 @@ def test_applymap(self):
29232923
assert_frame_equal(applied, self.frame * 2)
29242924
result = self.frame.applymap(type)
29252925

2926+
# GH #465, function returning tuples
2927+
result = self.frame.applymap(lambda x: (x, x))
2928+
self.assert_(isinstance(result['A'][0], tuple))
2929+
29262930
def test_filter(self):
29272931
# items
29282932

0 commit comments

Comments
 (0)