Skip to content

BUG: merge_asof raising ValueError for read-only ndarrays #53513

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
Jun 5, 2023

Conversation

lukemanley
Copy link
Member

@lukemanley lukemanley commented Jun 3, 2023

import pandas as pd

left = pd.Series([2], index=[2], name="left")
right = pd.Series([1], index=[1], name="right")

# setting read-only here results in the error below
left.index.values.flags.writeable = False

# ValueError: buffer source array is read-only
pd.merge_asof(left, right, left_index=True, right_index=True)

@lukemanley lukemanley added Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode labels Jun 3, 2023
@lukemanley lukemanley added this to the 2.1 milestone Jun 3, 2023
@lukemanley lukemanley requested a review from WillAyd as a code owner June 3, 2023 10:47
@WillAyd
Copy link
Member

WillAyd commented Jun 3, 2023

Does setting the memory views to const not have the same effect? For a while I thought we were trying to use memoryviews over numpy arrays in the Cython layer so would be better to stick to that design if it works. If not though still lgtm

@WillAyd
Copy link
Member

WillAyd commented Jun 3, 2023

Worth adding a test for this

@lukemanley
Copy link
Member Author

Does setting the memory views to const not have the same effect? For a while I thought we were trying to use memoryviews over numpy arrays in the Cython layer so would be better to stick to that design if it works. If not though still lgtm

I just tried setting const on the memory views and I got a compile error. Looking through the rest of that file it looks like most funcs use numpy arrays for numeric. There is a 3rd as_of join in that file (asof_join_nearest_on_X_by_Y) that already uses numpy arrays.

@lukemanley
Copy link
Member Author

Worth adding a test for this

I did include a test in this PR. Is there an additional test you'd like to see?

@WillAyd
Copy link
Member

WillAyd commented Jun 3, 2023

Ah sorry - missed the test looking from phone. And makes sense - the theory was to always use memoryviews but I don't think we ever got the practice to follow

@lukemanley
Copy link
Member Author

No worries, thanks for reviewing

@mroeschke mroeschke merged commit c409179 into pandas-dev:main Jun 5, 2023
@mroeschke
Copy link
Member

Thanks @lukemanley

topper-123 pushed a commit to topper-123/pandas that referenced this pull request Jun 5, 2023
…#53513)

* BUG: merge_asof raising ValueError for read-only ndarrays

* gh refs
@lukemanley lukemanley deleted the merge-asof-read-only-ndarray branch June 8, 2023 02:31
Daquisu pushed a commit to Daquisu/pandas that referenced this pull request Jul 8, 2023
…#53513)

* BUG: merge_asof raising ValueError for read-only ndarrays

* gh refs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants