Skip to content

Commit

Permalink
Converted kwargs to positional arguments in Cython layer
Browse files Browse the repository at this point in the history
  • Loading branch information
WillAyd committed Feb 6, 2018
1 parent 61d9c39 commit 6765acd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
13 changes: 6 additions & 7 deletions pandas/_libs/groupby.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ def group_last_object(ndarray[object, ndim=2] out,
def group_rank_object(ndarray[float64_t, ndim=2] out,
ndarray[object, ndim=2] values,
ndarray[int64_t] labels,
bint is_datetimelike, **kwargs):
bint is_datetimelike, object ties_method,
bint ascending, bint pct, object na_option):
"""
Only transforms on axis=0
"""
Expand All @@ -137,18 +138,16 @@ def group_rank_object(ndarray[float64_t, ndim=2] out,
int64_t grp_na_count=0
ndarray[int64_t] _as
ndarray[object] _values
bint pct, ascending, keep_na
bint keep_na

tiebreak = tiebreakers[kwargs['ties_method']]
ascending = kwargs['ascending']
pct = kwargs['pct']
keep_na = kwargs['na_option'] == 'keep'
tiebreak = tiebreakers[ties_method]
keep_na = na_option == 'keep'
N, K = (<object> values).shape

masked_vals = np.array(values[:, 0], copy=True)
mask = missing.isnaobj(masked_vals)

if ascending ^ (kwargs['na_option'] == 'top'):
if ascending ^ (na_option == 'top'):
nan_fill_val = np.inf
order = (masked_vals, mask, labels)
else:
Expand Down
13 changes: 6 additions & 7 deletions pandas/_libs/groupby_helper.pxi.in
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,8 @@ def group_nth_{{name}}(ndarray[{{dest_type2}}, ndim=2] out,
def group_rank_{{name}}(ndarray[float64_t, ndim=2] out,
ndarray[{{c_type}}, ndim=2] values,
ndarray[int64_t] labels,
bint is_datetimelike, **kwargs):
bint is_datetimelike, object ties_method,
bint ascending, bint pct, object na_option):
"""
Only transforms on axis=0
"""
Expand All @@ -462,13 +463,11 @@ def group_rank_{{name}}(ndarray[float64_t, ndim=2] out,
ndarray[int64_t] _as
ndarray[{{c_type}}] masked_vals
ndarray[uint8_t] mask
bint pct, ascending, keep_na
bint keep_na
{{c_type}} nan_fill_val

tiebreak = tiebreakers[kwargs['ties_method']]
ascending = kwargs['ascending']
pct = kwargs['pct']
keep_na = kwargs['na_option'] == 'keep'
tiebreak = tiebreakers[ties_method]
keep_na = na_option == 'keep'
N, K = (<object> values).shape

masked_vals = np.array(values[:, 0], copy=True)
Expand All @@ -478,7 +477,7 @@ def group_rank_{{name}}(ndarray[float64_t, ndim=2] out,
mask = np.isnan(masked_vals).astype(np.uint8)
{{endif}}

if ascending ^ (kwargs['na_option'] == 'top'):
if ascending ^ (na_option == 'top'):
{{if name == 'int64'}}
nan_fill_val = np.iinfo(np.int64).max
{{else}}
Expand Down
13 changes: 11 additions & 2 deletions pandas/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -2171,6 +2171,12 @@ def get_group_levels(self):
# ------------------------------------------------------------
# Aggregation functions

def _group_rank_wrapper(func, *args, **kwargs):
return func(*args, kwargs.get('ties_method', 'average'),
kwargs.get('ascending', True),
kwargs.get('pct', False),
kwargs.get('na_option', 'keep'))

_cython_functions = {
'aggregate': {
'add': 'group_add',
Expand All @@ -2195,7 +2201,10 @@ def get_group_levels(self):
'cumsum': 'group_cumsum',
'cummin': 'group_cummin',
'cummax': 'group_cummax',
'rank': 'group_rank',
'rank': {
'name': 'group_rank',
'f': _group_rank_wrapper
}
}
}

Expand Down Expand Up @@ -2424,7 +2433,7 @@ def _transform(self, result, values, comp_ids, transform_func,

chunk = chunk.squeeze()
transform_func(result[:, :, i], values,
comp_ids, is_datetimelike)
comp_ids, is_datetimelike, **kwargs)
else:
transform_func(result, values, comp_ids, is_datetimelike, **kwargs)

Expand Down

0 comments on commit 6765acd

Please sign in to comment.