File tree Expand file tree Collapse file tree 3 files changed +40
-7
lines changed Expand file tree Collapse file tree 3 files changed +40
-7
lines changed Original file line number Diff line number Diff line change @@ -50,8 +50,8 @@ pandas 0.5.1
50
50
- Add `orient` option to `Panel.from_dict` to ease creation of mixed-type
51
51
Panels (GH #359)
52
52
- Add `DataFrame.from_dict` with similar `orient` option
53
- - Can pass list of tuples or list of lists to `DataFrame.from_records` for
54
- fast conversion to DataFrame (GH #357)
53
+ - Can now pass list of tuples or list of lists to `DataFrame.from_records`
54
+ for fast conversion to DataFrame (GH #357)
55
55
56
56
**Improvements to existing features **
57
57
@@ -72,6 +72,9 @@ pandas 0.5.1
72
72
- Raise exception if dateutil 2.0 installed on Python 2.x runtime (GH #346)
73
73
- Significant GroupBy performance enhancement with multiple keys with many
74
74
"empty" combinations
75
+ - New Cython vectorized function `map_infer ` speeds up `Series.apply ` and
76
+ `Series.map ` significantly when passed elementwise Python function,
77
+ motivated by PR #355
75
78
76
79
**Bug fixes **
77
80
@@ -114,6 +117,7 @@ Thanks
114
117
- Jev Kuznetsov
115
118
- Dieter Vandenbussche
116
119
- rsamson
120
+ - Aman Thakral
117
121
118
122
pandas 0.5.0
119
123
============
Original file line number Diff line number Diff line change @@ -1331,8 +1331,8 @@ def map(self, arg):
1331
1331
new_values = common .take_1d (np .asarray (arg ), indexer )
1332
1332
return Series (new_values , index = self .index , name = self .name )
1333
1333
else :
1334
- return Series ([ arg ( x ) for x in self ], index = self . index ,
1335
- name = self .name )
1334
+ mapped = lib . map_infer ( self . values , arg )
1335
+ return Series ( mapped , index = self . index , name = self .name )
1336
1336
1337
1337
def apply (self , func ):
1338
1338
"""
@@ -1353,8 +1353,8 @@ def apply(self, func):
1353
1353
result = Series (result , index = self .index , name = self .name )
1354
1354
return result
1355
1355
except Exception :
1356
- return Series ([ func ( x ) for x in self ], index = self . index ,
1357
- name = self .name )
1356
+ mapped = lib . map_infer ( self . values , func )
1357
+ return Series ( mapped , index = self . index , name = self .name )
1358
1358
1359
1359
def align (self , other , join = 'outer' , copy = True ):
1360
1360
"""
Original file line number Diff line number Diff line change @@ -186,7 +186,7 @@ def ismember(ndarray arr, set values):
186
186
it = < flatiter> PyArray_IterNew(arr)
187
187
n = len (arr)
188
188
result = np.empty(n, dtype = np.uint8)
189
- for i from 0 <= i < n :
189
+ for i in range (n) :
190
190
val = PyArray_GETITEM(arr, PyArray_ITER_DATA(it))
191
191
if val in values:
192
192
result[i] = 1
@@ -196,6 +196,35 @@ def ismember(ndarray arr, set values):
196
196
197
197
return result.view(np.bool_)
198
198
199
+ def map_infer (ndarray arr , object f ):
200
+ '''
201
+ Substitute for np.vectorize with pandas-friendly dtype inference
202
+
203
+ Parameters
204
+ ----------
205
+ arr : ndarray
206
+ f : function
207
+
208
+ Returns
209
+ -------
210
+ mapped : ndarray
211
+ '''
212
+ cdef:
213
+ Py_ssize_t i, n
214
+ flatiter it
215
+ ndarray[object ] result
216
+ object val
217
+
218
+ it = < flatiter> PyArray_IterNew(arr)
219
+ n = len (arr)
220
+ result = np.empty(n, dtype = object )
221
+ for i in range (n):
222
+ val = PyArray_GETITEM(arr, PyArray_ITER_DATA(it))
223
+ result[i] = f(val)
224
+ PyArray_ITER_NEXT(it)
225
+
226
+ return maybe_convert_objects(result)
227
+
199
228
# ----------------------------------------------------------------------
200
229
# datetime / io related
201
230
You can’t perform that action at this time.
0 commit comments