Skip to content

BUG: Pass args and kwargs to empty #6953

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,8 @@ Bug Fixes
- Bug in C parser with leading whitespace (:issue:`3374`)
- Bug in C parser with ``delim_whitespace=True`` and ``\r``-delimited lines
- Bug in ``Series.rank`` and ``DataFrame.rank`` that caused small floats (<1e-13) to all receive the same rank (:issue:`6886`)
- Bug in ``DataFrame.apply`` with functions that used *args or **kwargs and returned
an empty result (:issue:`6952`)

pandas 0.13.1
-------------
Expand Down
10 changes: 6 additions & 4 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3313,7 +3313,7 @@ def apply(self, func, axis=0, broadcast=False, raw=False, reduce=None,
f = func

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

if isinstance(f, np.ufunc):
results = f(self.values)
Expand All @@ -3322,7 +3322,8 @@ def apply(self, func, axis=0, broadcast=False, raw=False, reduce=None,
else:
if not broadcast:
if not all(self.shape):
return self._apply_empty_result(func, axis, reduce)
return self._apply_empty_result(func, axis, reduce, *args,
**kwds)

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

def _apply_empty_result(self, func, axis, reduce):
def _apply_empty_result(self, func, axis, reduce, *args, **kwds):
if reduce is None:
reduce = False
try:
reduce = not isinstance(func(_EMPTY_SERIES), Series)
reduce = not isinstance(func(_EMPTY_SERIES, *args, **kwds),
Series)
except Exception:
pass

Expand Down