Skip to content

Commit 4500000

Browse files
dsaxtonpull[bot]
authored andcommitted
BUG: Fix isin with read-only target (#37181)
1 parent 927aa36 commit 4500000

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

doc/source/whatsnew/v1.1.4.rst

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Fixed regressions
2828
Bug fixes
2929
~~~~~~~~~
3030
- Bug causing ``groupby(...).sum()`` and similar to not preserve metadata (:issue:`29442`)
31+
- Bug in :meth:`Series.isin` and :meth:`DataFrame.isin` raising a ``ValueError`` when the target was read-only (:issue:`37174`)
3132

3233
.. ---------------------------------------------------------------------------
3334

pandas/_libs/hashtable_func_helper.pxi.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def duplicated_{{dtype}}(const {{c_type}}[:] values, object keep='first'):
208208
{{if dtype == 'object'}}
209209
def ismember_{{dtype}}(ndarray[{{c_type}}] arr, ndarray[{{c_type}}] values):
210210
{{else}}
211-
def ismember_{{dtype}}(const {{c_type}}[:] arr, {{c_type}}[:] values):
211+
def ismember_{{dtype}}(const {{c_type}}[:] arr, const {{c_type}}[:] values):
212212
{{endif}}
213213
"""
214214
Return boolean of values in arr on an

pandas/tests/frame/methods/test_isin.py

+9
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,12 @@ def test_isin_category_frame(self, values):
204204

205205
result = df.isin(values)
206206
tm.assert_frame_equal(result, expected)
207+
208+
def test_isin_read_only(self):
209+
# https://github.com/pandas-dev/pandas/issues/37174
210+
arr = np.array([1, 2, 3])
211+
arr.setflags(write=False)
212+
df = DataFrame([1, 2, 3])
213+
result = df.isin(arr)
214+
expected = DataFrame([True, True, True])
215+
tm.assert_frame_equal(result, expected)

pandas/tests/series/methods/test_isin.py

+9
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,12 @@ def test_isin_empty(self, empty):
8080

8181
result = s.isin(empty)
8282
tm.assert_series_equal(expected, result)
83+
84+
def test_isin_read_only(self):
85+
# https://github.com/pandas-dev/pandas/issues/37174
86+
arr = np.array([1, 2, 3])
87+
arr.setflags(write=False)
88+
s = Series([1, 2, 3])
89+
result = s.isin(arr)
90+
expected = Series([True, True, True])
91+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)