Skip to content

CLN: Use more memoryviews #58330

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

Merged
merged 2 commits into from
Apr 22, 2024
Merged
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
6 changes: 3 additions & 3 deletions pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ def has_infs(const floating[:] arr) -> bool:

@cython.boundscheck(False)
@cython.wraparound(False)
def has_only_ints_or_nan(floating[:] arr) -> bool:
def has_only_ints_or_nan(const floating[:] arr) -> bool:
cdef:
floating val
intp_t i
Expand Down Expand Up @@ -631,7 +631,7 @@ ctypedef fused int6432_t:

@cython.wraparound(False)
@cython.boundscheck(False)
def is_range_indexer(ndarray[int6432_t, ndim=1] left, Py_ssize_t n) -> bool:
def is_range_indexer(const int6432_t[:] left, Py_ssize_t n) -> bool:
"""
Perform an element by element comparison on 1-d integer arrays, meant for indexer
comparisons
Expand All @@ -652,7 +652,7 @@ def is_range_indexer(ndarray[int6432_t, ndim=1] left, Py_ssize_t n) -> bool:

@cython.wraparound(False)
@cython.boundscheck(False)
def is_sequence_range(ndarray[int6432_t, ndim=1] sequence, int64_t step) -> bool:
def is_sequence_range(const int6432_t[:] sequence, int64_t step) -> bool:
"""
Check if sequence is equivalent to a range with the specified step.
"""
Expand Down
4 changes: 2 additions & 2 deletions pandas/_libs/reshape.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ from pandas._libs.lib cimport c_is_list_like

@cython.wraparound(False)
@cython.boundscheck(False)
def unstack(numeric_object_t[:, :] values, const uint8_t[:] mask,
def unstack(const numeric_object_t[:, :] values, const uint8_t[:] mask,
Py_ssize_t stride, Py_ssize_t length, Py_ssize_t width,
numeric_object_t[:, :] new_values, uint8_t[:, :] new_mask) -> None:
"""
Expand Down Expand Up @@ -80,7 +80,7 @@ def unstack(numeric_object_t[:, :] values, const uint8_t[:] mask,

@cython.wraparound(False)
@cython.boundscheck(False)
def explode(ndarray[object] values):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we get here with a readonly ndarray?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like in our testing this array is always writable (from mgr.internal_values()), should this be readonly?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it can depend on what user passed to the constructor

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha. Well specifically here, we can't use const as that's not supported with object memoryviews

def explode(object[:] values):
"""
transform array list-likes to long form
preserve non-list entries
Expand Down