Skip to content

MAINT: Make take_1d accept readonly buffers. #12033

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 1 commit into from
Closed
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v0.18.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -508,3 +508,5 @@ Bug Fixes

- Removed ``millisecond`` property of ``DatetimeIndex``. This would always raise
a ``ValueError`` (:issue:`12019`).

- Bug in Series constructor with read-only data (:issue:`11502`)
35 changes: 28 additions & 7 deletions pandas/src/generate_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,7 @@
"""


take_1d_template = """
@cython.wraparound(False)
@cython.boundscheck(False)
def take_1d_%(name)s_%(dest)s(%(c_type_in)s[:] values,
int64_t[:] indexer,
%(c_type_out)s[:] out,
fill_value=np.nan):
inner_take_1d_template = """\
cdef:
Py_ssize_t i, n, idx
%(c_type_out)s fv
Expand All @@ -112,6 +106,33 @@ def take_1d_%(name)s_%(dest)s(%(c_type_in)s[:] values,
%(tab)s out[i] = %(preval)svalues[idx]%(postval)s
"""

take_1d_template = """\
@cython.wraparound(False)
@cython.boundscheck(False)
cdef inline take_1d_%(name)s_%(dest)s_memview(%(c_type_in)s[:] values,
int64_t[:] indexer,
%(c_type_out)s[:] out,
fill_value=np.nan):
""" + inner_take_1d_template + """

@cython.wraparound(False)
@cython.boundscheck(False)
def take_1d_%(name)s_%(dest)s(ndarray[%(c_type_in)s, ndim=1] values,
int64_t[:] indexer,
%(c_type_out)s[:] out,
fill_value=np.nan):

if values.flags.writeable:
# We can call the memoryview version of the code
take_1d_%(name)s_%(dest)s_memview(values, indexer, out,
fill_value=fill_value)
return

# We cannot use the memoryview version on readonly-buffers due to
# a limitation of Cython's typed memoryviews. Instead we can use
# the slightly slower Cython ndarray type directly.
""" + inner_take_1d_template

inner_take_2d_axis0_template = """\
cdef:
Py_ssize_t i, j, k, n, idx
Expand Down
Loading