Skip to content

Commit ffb582c

Browse files
gfyoungjreback
authored andcommitted
Removed unnecessary params in cum_func
Picks up from #13167 by properly removing the parameters and ensuring that `numpy` compatibility has been maintained. The current test suite does a good job of checking that already, so no tests were added. Closes #13541. Author: gfyoung <[email protected]> Closes #13550 from gfyoung/cum-func-cleanup and squashes the following commits: 6ba7a77 [gfyoung] Removed unnecessary params in cum_func
1 parent a01644c commit ffb582c

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

pandas/compat/numpy/function.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from numpy import ndarray
2222
from pandas.util.validators import (validate_args, validate_kwargs,
2323
validate_args_and_kwargs)
24-
from pandas.core.common import is_integer, UnsupportedFunctionCall
24+
from pandas.core.common import is_bool, is_integer, UnsupportedFunctionCall
2525
from pandas.compat import OrderedDict
2626

2727

@@ -148,10 +148,26 @@ def validate_clip_with_axis(axis, args, kwargs):
148148
CUM_FUNC_DEFAULTS = OrderedDict()
149149
CUM_FUNC_DEFAULTS['dtype'] = None
150150
CUM_FUNC_DEFAULTS['out'] = None
151-
validate_cum_func = CompatValidator(CUM_FUNC_DEFAULTS, method='kwargs')
151+
validate_cum_func = CompatValidator(CUM_FUNC_DEFAULTS, method='both',
152+
max_fname_arg_count=1)
152153
validate_cumsum = CompatValidator(CUM_FUNC_DEFAULTS, fname='cumsum',
153154
method='both', max_fname_arg_count=1)
154155

156+
157+
def validate_cum_func_with_skipna(skipna, args, kwargs, name):
158+
"""
159+
If this function is called via the 'numpy' library, the third
160+
parameter in its signature is 'dtype', which takes either a
161+
'numpy' dtype or 'None', so check if the 'skipna' parameter is
162+
a boolean or not
163+
"""
164+
if not is_bool(skipna):
165+
args = (skipna,) + args
166+
skipna = True
167+
168+
validate_cum_func(args, kwargs, fname=name)
169+
return skipna
170+
155171
LOGICAL_FUNC_DEFAULTS = dict(out=None)
156172
validate_logical_func = CompatValidator(LOGICAL_FUNC_DEFAULTS, method='kwargs')
157173

pandas/core/generic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5484,8 +5484,8 @@ def _make_cum_function(cls, name, name1, name2, axis_descr, desc, accum_func,
54845484
axis_descr=axis_descr)
54855485
@Appender("Return cumulative {0} over requested axis.".format(name) +
54865486
_cnum_doc)
5487-
def cum_func(self, axis=None, dtype=None, out=None, skipna=True, **kwargs):
5488-
nv.validate_cum_func(tuple(), kwargs, fname=name)
5487+
def cum_func(self, axis=None, skipna=True, *args, **kwargs):
5488+
skipna = nv.validate_cum_func_with_skipna(skipna, args, kwargs, name)
54895489
if axis is None:
54905490
axis = self._stat_axis_number
54915491
else:

0 commit comments

Comments
 (0)