Conversation

lukemanley
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)

@lukemanleylukemanley added Bug ReshapingConcat, Merge/Join, Stack/Unstack, Explodelabels Jun 3, 2023
@lukemanleylukemanley added this to the 2.1 milestone Jun 3, 2023
@lukemanleylukemanley requested a review from WillAyd as a code owner June 3, 2023 10:47
@WillAyd

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

Worth adding a test for this

@lukemanley

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

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

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

No worries, thanks for reviewing

@mroeschkemroeschke merged commit c409179 into pandas-dev:main Jun 5, 2023
@mroeschke

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
@lukemanleylukemanley 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 . Already have an account? Sign in to comment
Bug ReshapingConcat, Merge/Join, Stack/Unstack, Explode
None yet

Successfully merging this pull request may close these issues.