Skip to content

Commit 682ac7f

Browse files
author
Tom Augspurger
committed
Merge pull request #6953 from TomAugspurger/_apply_empty_result-args
BUG: Pass args and kwargs to empty
2 parents a5cab86 + 753a9d3 commit 682ac7f

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

doc/source/release.rst

+2
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,8 @@ Bug Fixes
420420
- Bug in C parser with leading whitespace (:issue:`3374`)
421421
- Bug in C parser with ``delim_whitespace=True`` and ``\r``-delimited lines
422422
- Bug in ``Series.rank`` and ``DataFrame.rank`` that caused small floats (<1e-13) to all receive the same rank (:issue:`6886`)
423+
- Bug in ``DataFrame.apply`` with functions that used *args or **kwargs and returned
424+
an empty result (:issue:`6952`)
423425
424426
pandas 0.13.1
425427
-------------

pandas/core/frame.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -3313,7 +3313,7 @@ def apply(self, func, axis=0, broadcast=False, raw=False, reduce=None,
33133313
f = func
33143314

33153315
if len(self.columns) == 0 and len(self.index) == 0:
3316-
return self._apply_empty_result(func, axis, reduce)
3316+
return self._apply_empty_result(func, axis, reduce, *args, **kwds)
33173317

33183318
if isinstance(f, np.ufunc):
33193319
results = f(self.values)
@@ -3322,7 +3322,8 @@ def apply(self, func, axis=0, broadcast=False, raw=False, reduce=None,
33223322
else:
33233323
if not broadcast:
33243324
if not all(self.shape):
3325-
return self._apply_empty_result(func, axis, reduce)
3325+
return self._apply_empty_result(func, axis, reduce, *args,
3326+
**kwds)
33263327

33273328
if raw and not self._is_mixed_type:
33283329
return self._apply_raw(f, axis)
@@ -3333,11 +3334,12 @@ def apply(self, func, axis=0, broadcast=False, raw=False, reduce=None,
33333334
else:
33343335
return self._apply_broadcast(f, axis)
33353336

3336-
def _apply_empty_result(self, func, axis, reduce):
3337+
def _apply_empty_result(self, func, axis, reduce, *args, **kwds):
33373338
if reduce is None:
33383339
reduce = False
33393340
try:
3340-
reduce = not isinstance(func(_EMPTY_SERIES), Series)
3341+
reduce = not isinstance(func(_EMPTY_SERIES, *args, **kwds),
3342+
Series)
33413343
except Exception:
33423344
pass
33433345

0 commit comments

Comments
 (0)