File tree 3 files changed +13
-1
lines changed
3 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -237,6 +237,7 @@ Other API Changes
237
237
238
238
- ``CParserError`` has been renamed to ``ParserError`` in ``pd.read_csv`` and will be removed in the future (:issue:`12665`)
239
239
- ``SparseArray.cumsum()`` and ``SparseSeries.cumsum()`` will now always return ``SparseArray`` and ``SparseSeries`` respectively (:issue:`12855`)
240
+ - ``DataFrame.applymap()`` with an empty ``DataFrame`` will return a copy of the empty ``DataFrame`` instead of a ``Series`` (:issue:`8222`)
240
241
241
242
.. _whatsnew_0200.deprecations:
242
243
@@ -286,7 +287,6 @@ Bug Fixes
286
287
- Bug in ``DataFrame.sort_values()`` when sorting by multiple columns where one column is of type ``int64`` and contains ``NaT`` (:issue:`14922`)
287
288
288
289
289
-
290
290
- Bug in ``pd.read_msgpack()`` in which ``Series`` categoricals were being improperly processed (:issue:`14901`)
291
291
- Bug in ``Series.ffill()`` with mixed dtypes containing tz-aware datetimes. (:issue:`14956`)
292
292
Original file line number Diff line number Diff line change @@ -4288,6 +4288,8 @@ def applymap(self, func):
4288
4288
4289
4289
# if we have a dtype == 'M8[ns]', provide boxed values
4290
4290
def infer (x ):
4291
+ if x .empty :
4292
+ return lib .map_infer (x , func )
4291
4293
return lib .map_infer (x .asobject , func )
4292
4294
4293
4295
return self .apply (infer )
Original file line number Diff line number Diff line change @@ -405,6 +405,16 @@ def test_applymap(self):
405
405
for f in ['datetime' , 'timedelta' ]:
406
406
self .assertEqual (result .loc [0 , f ], str (df .loc [0 , f ]))
407
407
408
+ # GH 8222
409
+ empty_frames = [pd .DataFrame (),
410
+ pd .DataFrame (columns = list ('ABC' )),
411
+ pd .DataFrame (index = list ('ABC' )),
412
+ pd .DataFrame ({'A' : [], 'B' : [], 'C' : []})]
413
+ for frame in empty_frames :
414
+ for func in [round , lambda x : x ]:
415
+ result = frame .applymap (func )
416
+ tm .assert_frame_equal (result , frame )
417
+
408
418
def test_applymap_box (self ):
409
419
# ufunc will not be boxed. Same test cases as the test_map_box
410
420
df = pd .DataFrame ({'a' : [pd .Timestamp ('2011-01-01' ),
You can’t perform that action at this time.
0 commit comments