From ff88e712ebc0b0966b67fb0a013c27be9b3f2ff0 Mon Sep 17 00:00:00 2001 From: Daniel Saxton Date: Fri, 16 Oct 2020 19:00:40 -0500 Subject: [PATCH 1/5] BUG: Fix isin with read-only target --- doc/source/whatsnew/v1.2.0.rst | 1 + pandas/_libs/hashtable_func_helper.pxi.in | 2 +- pandas/tests/frame/methods/test_isin.py | 9 +++++++++ pandas/tests/series/methods/test_isin.py | 9 +++++++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index c9a1dbd0ae90d..48601368b8db6 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -498,6 +498,7 @@ Other - Fixed metadata propagation in the :class:`Series.dt` and :class:`Series.str` accessors (:issue:`28283`) - Bug in :meth:`Index.union` behaving differently depending on whether operand is a :class:`Index` or other list-like (:issue:`36384`) - Passing an array with 2 or more dimensions to the :class:`Series` constructor now raises the more specific ``ValueError``, from a bare ``Exception`` previously (:issue:`35744`) +- Bug in :meth:`Series.isin` and :meth:`DataFrame.isin` raising a ``ValueError`` when the target was read-only (:issue:`37174`) .. --------------------------------------------------------------------------- diff --git a/pandas/_libs/hashtable_func_helper.pxi.in b/pandas/_libs/hashtable_func_helper.pxi.in index fcd081f563f92..4a466ada765ca 100644 --- a/pandas/_libs/hashtable_func_helper.pxi.in +++ b/pandas/_libs/hashtable_func_helper.pxi.in @@ -208,7 +208,7 @@ def duplicated_{{dtype}}(const {{c_type}}[:] values, object keep='first'): {{if dtype == 'object'}} def ismember_{{dtype}}(ndarray[{{c_type}}] arr, ndarray[{{c_type}}] values): {{else}} -def ismember_{{dtype}}(const {{c_type}}[:] arr, {{c_type}}[:] values): +def ismember_{{dtype}}(const {{c_type}}[:] arr, const {{c_type}}[:] values): {{endif}} """ Return boolean of values in arr on an diff --git a/pandas/tests/frame/methods/test_isin.py b/pandas/tests/frame/methods/test_isin.py index 35d45bd00131b..29a3a0106c56c 100644 --- a/pandas/tests/frame/methods/test_isin.py +++ b/pandas/tests/frame/methods/test_isin.py @@ -204,3 +204,12 @@ def test_isin_category_frame(self, values): result = df.isin(values) tm.assert_frame_equal(result, expected) + + def test_isin_read_only(self): + # https://github.com/pandas-dev/pandas/issues/37174 + arr = np.array([1, 2, 3]) + arr.setflags(write=False) + df = DataFrame([1, 2, 3]) + result = df.isin(arr) + expected = DataFrame([True, True, True]) + tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/series/methods/test_isin.py b/pandas/tests/series/methods/test_isin.py index 3836c1d56bf87..093ea904a1c44 100644 --- a/pandas/tests/series/methods/test_isin.py +++ b/pandas/tests/series/methods/test_isin.py @@ -80,3 +80,12 @@ def test_isin_empty(self, empty): result = s.isin(empty) tm.assert_series_equal(expected, result) + + def test_isin_read_only(self): + # https://github.com/pandas-dev/pandas/issues/37174 + arr = np.array([1, 2, 3]) + arr.setflags(write=False) + s = pd.Series([1, 2, 3]) + result = s.isin(arr) + expected = Series([True, True, True]) + tm.assert_series_equal(result, expected) From a0c0ea00b0c9f338ef3ba3e72219b89ca713d090 Mon Sep 17 00:00:00 2001 From: Daniel Saxton Date: Fri, 16 Oct 2020 19:30:41 -0500 Subject: [PATCH 2/5] Note --- doc/source/whatsnew/v1.1.4.rst | 1 + doc/source/whatsnew/v1.2.0.rst | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/doc/source/whatsnew/v1.1.4.rst b/doc/source/whatsnew/v1.1.4.rst index 6892fb62028c9..f3113ccfc21b5 100644 --- a/doc/source/whatsnew/v1.1.4.rst +++ b/doc/source/whatsnew/v1.1.4.rst @@ -35,6 +35,7 @@ Bug fixes Other ~~~~~ +- Bug in :meth:`Series.isin` and :meth:`DataFrame.isin` raising a ``ValueError`` when the target was read-only (:issue:`37174`) - .. --------------------------------------------------------------------------- diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index 48601368b8db6..dfbbb456f50b6 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -348,8 +348,7 @@ Datetimelike Timedelta ^^^^^^^^^ - Bug in :class:`TimedeltaIndex`, :class:`Series`, and :class:`DataFrame` floor-division with ``timedelta64`` dtypes and ``NaT`` in the denominator (:issue:`35529`) -- -- +- Bug in parsing of ISO 8601 durations in :class:`Timedelta`, :meth:`pd.to_datetime` (:issue:`37159`, fixes :issue:`29773` and :issue:`36204`) Timezones ^^^^^^^^^ @@ -498,7 +497,6 @@ Other - Fixed metadata propagation in the :class:`Series.dt` and :class:`Series.str` accessors (:issue:`28283`) - Bug in :meth:`Index.union` behaving differently depending on whether operand is a :class:`Index` or other list-like (:issue:`36384`) - Passing an array with 2 or more dimensions to the :class:`Series` constructor now raises the more specific ``ValueError``, from a bare ``Exception`` previously (:issue:`35744`) -- Bug in :meth:`Series.isin` and :meth:`DataFrame.isin` raising a ``ValueError`` when the target was read-only (:issue:`37174`) .. --------------------------------------------------------------------------- From 87ba9d935c84f023b5984aebce7cc8a47661259c Mon Sep 17 00:00:00 2001 From: Daniel Saxton Date: Fri, 16 Oct 2020 20:14:50 -0500 Subject: [PATCH 3/5] Fix --- pandas/tests/series/methods/test_isin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/series/methods/test_isin.py b/pandas/tests/series/methods/test_isin.py index 093ea904a1c44..62766c692f4df 100644 --- a/pandas/tests/series/methods/test_isin.py +++ b/pandas/tests/series/methods/test_isin.py @@ -85,7 +85,7 @@ def test_isin_read_only(self): # https://github.com/pandas-dev/pandas/issues/37174 arr = np.array([1, 2, 3]) arr.setflags(write=False) - s = pd.Series([1, 2, 3]) + s = Series([1, 2, 3]) result = s.isin(arr) expected = Series([True, True, True]) tm.assert_series_equal(result, expected) From fd617aff857ce7b2e5b824ec32f063d66ea3813c Mon Sep 17 00:00:00 2001 From: Daniel Saxton Date: Sat, 17 Oct 2020 10:20:19 -0500 Subject: [PATCH 4/5] Note --- doc/source/whatsnew/v1.1.4.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v1.1.4.rst b/doc/source/whatsnew/v1.1.4.rst index f3113ccfc21b5..563ad169dd93c 100644 --- a/doc/source/whatsnew/v1.1.4.rst +++ b/doc/source/whatsnew/v1.1.4.rst @@ -33,8 +33,8 @@ Bug fixes .. _whatsnew_114.other: -Other -~~~~~ +Indexing +~~~~~~~~ - Bug in :meth:`Series.isin` and :meth:`DataFrame.isin` raising a ``ValueError`` when the target was read-only (:issue:`37174`) - From 3bc34219f77d72581b35f537c989f2746c216f47 Mon Sep 17 00:00:00 2001 From: Daniel Saxton Date: Sat, 17 Oct 2020 10:55:05 -0500 Subject: [PATCH 5/5] Note --- doc/source/whatsnew/v1.1.4.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/source/whatsnew/v1.1.4.rst b/doc/source/whatsnew/v1.1.4.rst index 563ad169dd93c..d5b6abd9f9de4 100644 --- a/doc/source/whatsnew/v1.1.4.rst +++ b/doc/source/whatsnew/v1.1.4.rst @@ -28,14 +28,14 @@ Fixed regressions Bug fixes ~~~~~~~~~ - Bug causing ``groupby(...).sum()`` and similar to not preserve metadata (:issue:`29442`) +- Bug in :meth:`Series.isin` and :meth:`DataFrame.isin` raising a ``ValueError`` when the target was read-only (:issue:`37174`) .. --------------------------------------------------------------------------- .. _whatsnew_114.other: -Indexing -~~~~~~~~ -- Bug in :meth:`Series.isin` and :meth:`DataFrame.isin` raising a ``ValueError`` when the target was read-only (:issue:`37174`) +Other +~~~~~ - .. ---------------------------------------------------------------------------