def _compute(self, arrays, dates, assets, mask): """ For each row in the input, compute a like-shaped array of per-row ranks. """ inv_mask = ~mask data = arrays[0].copy() data[inv_mask] = nan # OPTIMIZATION: Fast path the default case with our own specialized # Cython implementation. if self._method == 'ordinal': result = rankdata_2d_ordinal(data) else: # FUTURE OPTIMIZATION: # Write a less general "apply to rows" method that doesn't do all # the extra work that apply_along_axis does. result = apply_along_axis(rankdata, 1, data, method=self._method) # rankdata will sort nan values into last place, but we want our # nans to propagate, so explicitly re-apply. result[inv_mask] = nan return result
def compute_from_arrays(self, arrays, mask): """ For each row in the input, compute a like-shaped array of per-row ranks. """ # OPTIMIZATION: Fast path the default value with our own specialized # implementation. if self._method == 'ordinal': result = rankdata_2d_ordinal(arrays[0]) else: # FUTURE OPTIMIZATION: # Write a less general "apply to rows" method that doesn't do all # the extra work that apply_along_axis does. result = apply_along_axis( rankdata, 1, arrays[0], method=self._method, ) # rankdata will sort nan values into last place, but we want our # nans to propagate, so explicitly re-apply result[~mask.values] = nan return result