Skip to content

Introduction of RangeIndex #9961

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

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 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
42 changes: 42 additions & 0 deletions pandas/algos.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2349,5 +2349,47 @@ cdef inline float64_t _median_linear(float64_t* a, int n):

return result

@cython.wraparound(False)
@cython.boundscheck(False)
def groupby_range(range_index, ndarray labels):
'''
Assigns indices incrementing by step to each index of labels and groups by
uniques.
'''
cdef Py_ssize_t i, length, idx, step
cdef dict result = {}
cdef list members
cdef object key
length = len(range_index)
if length != len(labels):
raise ValueError("len(index) != len(labels)")
idx = range_index.start
step = range_index.step
for i in range(length):
key = labels[i]
if key in result:
result[key].append(idx)
else:
result[key] = [idx]
idx += step
return result

@cython.wraparound(False)
@cython.boundscheck(False)
def arrmap_range(range_index, object func):
cdef Py_ssize_t i, idx, step, length
length = len(range_index)
cdef ndarray[object] result = np.empty(length, dtype=np.object_)

from pandas.lib import maybe_convert_objects

idx = range_index.start
step = range_index.step
for i in range(length):
result[i] = func(idx)
idx += step
return maybe_convert_objects(result)


include "join.pyx"
include "generated.pyx"
Loading