From 753a9d3177e1a1dea67eae3d4ee88e446552af56 Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Thu, 24 Apr 2014 09:00:41 -0500 Subject: [PATCH] BUG: Pass args and kwargs to empty --- doc/source/release.rst | 2 ++ pandas/core/frame.py | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/doc/source/release.rst b/doc/source/release.rst index 49656046129ca..4a7ef0ed70828 100644 --- a/doc/source/release.rst +++ b/doc/source/release.rst @@ -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 ------------- diff --git a/pandas/core/frame.py b/pandas/core/frame.py index bce09b673ad75..fcbd0688792fb 100755 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -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) @@ -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) @@ -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