Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLN: refactor roll_generic to call roll_generic_with_indexer #27523

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 36 additions & 9 deletions pandas/_libs/window.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1583,14 +1583,46 @@ def roll_generic(object obj,
int offset, object func, bint raw,
object args, object kwargs):
cdef:
ndarray[float64_t] output, counts, bufarr
ndarray[float64_t, cast=True] arr
float64_t *buf
float64_t *oldbuf
int64_t nobs = 0, i, j, s, e, N
int64_t N
bint is_variable
ndarray[int64_t] start, end

arr = np.asarray(obj)

# ndarray input
if raw:
if not arr.flags.c_contiguous:
arr = arr.copy('C')

start, end, N, _ , minp, is_variable = get_window_indexer(arr, win,
minp, index,
closed,
floor=0)

return roll_generic_with_indexer(obj,
win, minp, index, closed,
offset, func, raw,
start, end, N,
is_variable,
args, kwargs
)


def roll_generic_with_indexer(object obj,
int64_t win, int64_t minp, object index, object closed,
int offset, object func, bint raw,
ndarray[int64_t] start, ndarray[int64_t] end, int64_t N,
bint is_variable,
object args, object kwargs):
cdef:
ndarray[float64_t] output, bufarr
ndarray[float64_t, cast=True] arr
float64_t *buf
float64_t *oldbuf
int64_t nobs = 0, i, j, s, e
ndarray[float64_t] counts

n = len(obj)
if n == 0:
return obj
Expand All @@ -1606,11 +1638,6 @@ def roll_generic(object obj,
np.array([0.] * offset)]),
win, minp, index, closed)[offset:]

start, end, N, win, minp, is_variable = get_window_indexer(arr, win,
minp, index,
closed,
floor=0)

output = np.empty(N, dtype=float)

if is_variable:
Expand Down