Skip to content

Commit 4538cdc

Browse files
committed
Converted kwargs to positional arguments in Cython layer
1 parent 012156c commit 4538cdc

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

pandas/_libs/groupby.pyx

+6-7
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ def group_last_object(ndarray[object, ndim=2] out,
126126
def group_rank_object(ndarray[float64_t, ndim=2] out,
127127
ndarray[object, ndim=2] values,
128128
ndarray[int64_t] labels,
129-
bint is_datetimelike, **kwargs):
129+
bint is_datetimelike, object ties_method,
130+
bint ascending, bint pct, object na_option):
130131
"""
131132
Only transforms on axis=0
132133
"""
@@ -137,18 +138,16 @@ def group_rank_object(ndarray[float64_t, ndim=2] out,
137138
int64_t grp_na_count=0
138139
ndarray[int64_t] _as
139140
ndarray[object] _values
140-
bint pct, ascending, keep_na
141+
bint keep_na
141142

142-
tiebreak = tiebreakers[kwargs['ties_method']]
143-
ascending = kwargs['ascending']
144-
pct = kwargs['pct']
145-
keep_na = kwargs['na_option'] == 'keep'
143+
tiebreak = tiebreakers[ties_method]
144+
keep_na = na_option == 'keep'
146145
N, K = (<object> values).shape
147146

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

151-
if ascending ^ (kwargs['na_option'] == 'top'):
150+
if ascending ^ (na_option == 'top'):
152151
nan_fill_val = np.inf
153152
order = (masked_vals, mask, labels)
154153
else:

pandas/_libs/groupby_helper.pxi.in

+6-7
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,8 @@ def group_nth_{{name}}(ndarray[{{dest_type2}}, ndim=2] out,
450450
def group_rank_{{name}}(ndarray[float64_t, ndim=2] out,
451451
ndarray[{{c_type}}, ndim=2] values,
452452
ndarray[int64_t] labels,
453-
bint is_datetimelike, **kwargs):
453+
bint is_datetimelike, object ties_method,
454+
bint ascending, bint pct, object na_option):
454455
"""
455456
Only transforms on axis=0
456457
"""
@@ -462,13 +463,11 @@ def group_rank_{{name}}(ndarray[float64_t, ndim=2] out,
462463
ndarray[int64_t] _as
463464
ndarray[{{c_type}}] masked_vals
464465
ndarray[uint8_t] mask
465-
bint pct, ascending, keep_na
466+
bint keep_na
466467
{{c_type}} nan_fill_val
467468

468-
tiebreak = tiebreakers[kwargs['ties_method']]
469-
ascending = kwargs['ascending']
470-
pct = kwargs['pct']
471-
keep_na = kwargs['na_option'] == 'keep'
469+
tiebreak = tiebreakers[ties_method]
470+
keep_na = na_option == 'keep'
472471
N, K = (<object> values).shape
473472

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

481-
if ascending ^ (kwargs['na_option'] == 'top'):
480+
if ascending ^ (na_option == 'top'):
482481
{{if name == 'int64'}}
483482
nan_fill_val = np.iinfo(np.int64).max
484483
{{else}}

pandas/core/groupby.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -2171,6 +2171,12 @@ def get_group_levels(self):
21712171
# ------------------------------------------------------------
21722172
# Aggregation functions
21732173

2174+
def _group_rank_wrapper(func, *args, **kwargs):
2175+
return func(*args, kwargs.get('ties_method', 'average'),
2176+
kwargs.get('ascending', True),
2177+
kwargs.get('pct', False),
2178+
kwargs.get('na_option', 'keep'))
2179+
21742180
_cython_functions = {
21752181
'aggregate': {
21762182
'add': 'group_add',
@@ -2195,7 +2201,10 @@ def get_group_levels(self):
21952201
'cumsum': 'group_cumsum',
21962202
'cummin': 'group_cummin',
21972203
'cummax': 'group_cummax',
2198-
'rank': 'group_rank',
2204+
'rank': {
2205+
'name': 'group_rank',
2206+
'f': _group_rank_wrapper
2207+
}
21992208
}
22002209
}
22012210

@@ -2424,7 +2433,7 @@ def _transform(self, result, values, comp_ids, transform_func,
24242433

24252434
chunk = chunk.squeeze()
24262435
transform_func(result[:, :, i], values,
2427-
comp_ids, is_datetimelike)
2436+
comp_ids, is_datetimelike, **kwargs)
24282437
else:
24292438
transform_func(result, values, comp_ids, is_datetimelike, **kwargs)
24302439

0 commit comments

Comments
 (0)