From 2eb106cf13ea3176b4401a0185a661884b58ed09 Mon Sep 17 00:00:00 2001 From: KevsterAmp Date: Fri, 22 Nov 2024 21:41:52 +0800 Subject: [PATCH 01/13] add FutureWarning to __array__ --- pandas/core/arrays/arrow/array.py | 10 ++++++++++ pandas/core/arrays/categorical.py | 10 ++++++++++ pandas/core/arrays/datetimelike.py | 10 ++++++++++ pandas/core/arrays/interval.py | 10 ++++++++++ pandas/core/arrays/masked.py | 11 +++++++++++ pandas/core/arrays/period.py | 10 ++++++++++ pandas/core/arrays/sparse/array.py | 10 ++++++++++ pandas/core/generic.py | 10 ++++++++++ pandas/core/indexes/multi.py | 10 ++++++++++ 9 files changed, 91 insertions(+) diff --git a/pandas/core/arrays/arrow/array.py b/pandas/core/arrays/arrow/array.py index 0c1e1d0c63c85..6f3843a4c6a6d 100644 --- a/pandas/core/arrays/arrow/array.py +++ b/pandas/core/arrays/arrow/array.py @@ -663,6 +663,16 @@ def __array__( ) -> np.ndarray: """Correctly construct numpy arrays when passed to `np.asarray()`.""" if copy is False: + import warnings + + from pandas.util._exceptions import find_stack_level + + warnings.warn( + "Numpy>=2.0 changed copy keyword's behavior, making copy=False" + "raise an error when a zero-copy numpy array is not possible", + FutureWarning, + stacklevel=find_stack_level(), + ) # TODO: By using `zero_copy_only` it may be possible to implement this raise ValueError( "Unable to avoid copy while creating an array as requested." diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index 3383f35bb7d55..8e0932aa1ea72 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -1672,6 +1672,16 @@ def __array__( array(['a', 'b'], dtype=object) """ if copy is False: + import warnings + + from pandas.util._exceptions import find_stack_level + + warnings.warn( + "Numpy>=2.0 changed copy keyword's behavior, making copy=False " + "raise an error when a zero-copy numpy array is not possible", + FutureWarning, + stacklevel=find_stack_level(), + ) raise ValueError( "Unable to avoid copy while creating an array as requested." ) diff --git a/pandas/core/arrays/datetimelike.py b/pandas/core/arrays/datetimelike.py index 990116bad13d1..01ea5dd911f73 100644 --- a/pandas/core/arrays/datetimelike.py +++ b/pandas/core/arrays/datetimelike.py @@ -359,6 +359,16 @@ def __array__( # used for Timedelta/DatetimeArray, overwritten by PeriodArray if is_object_dtype(dtype): if copy is False: + import warnings + + from pandas.util._exceptions import find_stack_level + + warnings.warn( + "Numpy>=2.0 changed copy keyword's behavior, making copy=False" + "raise an error when a zero-copy numpy array is not possible", + FutureWarning, + stacklevel=find_stack_level(), + ) raise ValueError( "Unable to avoid copy while creating an array as requested." ) diff --git a/pandas/core/arrays/interval.py b/pandas/core/arrays/interval.py index 5aac3d3b28db5..7fb86618b7447 100644 --- a/pandas/core/arrays/interval.py +++ b/pandas/core/arrays/interval.py @@ -1575,6 +1575,16 @@ def __array__( objects (with dtype='object') """ if copy is False: + import warnings + + from pandas.util._exceptions import find_stack_level + + warnings.warn( + "Numpy>=2.0 changed copy keyword's behavior, making copy=False" + "raise an error when a zero-copy numpy array is not possible", + FutureWarning, + stacklevel=find_stack_level(), + ) raise ValueError( "Unable to avoid copy while creating an array as requested." ) diff --git a/pandas/core/arrays/masked.py b/pandas/core/arrays/masked.py index 0e839dc7a80bb..4935c649d62e9 100644 --- a/pandas/core/arrays/masked.py +++ b/pandas/core/arrays/masked.py @@ -604,6 +604,17 @@ def __array__( if not self._hasna: # special case, here we can simply return the underlying data return np.array(self._data, dtype=dtype, copy=copy) + + import warnings + + from pandas.util._exceptions import find_stack_level + + warnings.warn( + "Numpy>=2.0 changed copy keyword's behavior, making copy=False" + "raise an error when a zero-copy numpy array is not possible", + FutureWarning, + stacklevel=find_stack_level(), + ) raise ValueError( "Unable to avoid copy while creating an array as requested." ) diff --git a/pandas/core/arrays/period.py b/pandas/core/arrays/period.py index aad7737b8dd94..9326358d1eaa7 100644 --- a/pandas/core/arrays/period.py +++ b/pandas/core/arrays/period.py @@ -415,6 +415,16 @@ def __array__( return np.array(self.asi8, dtype=dtype) if copy is False: + import warnings + + from pandas.util._exceptions import find_stack_level + + warnings.warn( + "Numpy>=2.0 changed copy keyword's behavior, making copy=False" + "raise an error when a zero-copy numpy array is not possible", + FutureWarning, + stacklevel=find_stack_level(), + ) raise ValueError( "Unable to avoid copy while creating an array as requested." ) diff --git a/pandas/core/arrays/sparse/array.py b/pandas/core/arrays/sparse/array.py index 13577e366d54b..53c577fde7e65 100644 --- a/pandas/core/arrays/sparse/array.py +++ b/pandas/core/arrays/sparse/array.py @@ -562,6 +562,16 @@ def __array__( return self.sp_values if copy is False: + import warnings + + from pandas.util._exceptions import find_stack_level + + warnings.warn( + "Numpy>=2.0 changed copy keyword's behavior, making copy=False" + "raise an error when a zero-copy numpy array is not possible", + FutureWarning, + stacklevel=find_stack_level(), + ) raise ValueError( "Unable to avoid copy while creating an array as requested." ) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index e55a54112ee72..65b76962a7932 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2152,6 +2152,16 @@ def __array__( if copy is False and not self._mgr.is_single_block and not self.empty: # check this manually, otherwise ._values will already return a copy # and np.array(values, copy=False) will not raise an error + import warnings + + from pandas.util._exceptions import find_stack_level + + warnings.warn( + "Numpy>=2.0 changed the copy keyword behavior, making copy=False" + "raise an error when a zero-copy numpy array is not possible.", + FutureWarning, + stacklevel=find_stack_level(), + ) raise ValueError( "Unable to avoid copy while creating an array as requested." ) diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index 7cb28214c7289..3cd04450e0144 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -1314,6 +1314,16 @@ def __array__(self, dtype=None, copy=None) -> np.ndarray: """the array interface, return my values""" if copy is False: # self.values is always a newly construct array, so raise. + import warnings + + from pandas.util._exceptions import find_stack_level + + warnings.warn( + "Numpy>=2.0 changed copy keyword's behavior, making copy=False" + "raise an error when a zero-copy numpy array is not possible", + FutureWarning, + stacklevel=find_stack_level(), + ) raise ValueError( "Unable to avoid copy while creating an array as requested." ) From f0bec10715b386da5ae713eb94c3382deb363964 Mon Sep 17 00:00:00 2001 From: KevsterAmp Date: Mon, 25 Nov 2024 19:22:43 +0800 Subject: [PATCH 02/13] move imports on top, add better warning message, remove error raise --- pandas/core/arrays/arrow/array.py | 17 +++++++---------- pandas/core/arrays/categorical.py | 14 +++++--------- pandas/core/arrays/datetimelike.py | 16 +++++++--------- pandas/core/arrays/interval.py | 15 ++++++--------- pandas/core/arrays/masked.py | 15 ++++++--------- pandas/core/arrays/period.py | 14 +++++--------- pandas/core/arrays/sparse/array.py | 14 +++++--------- pandas/core/generic.py | 16 ++++++---------- pandas/core/indexes/multi.py | 14 +++++--------- 9 files changed, 52 insertions(+), 83 deletions(-) diff --git a/pandas/core/arrays/arrow/array.py b/pandas/core/arrays/arrow/array.py index 6f3843a4c6a6d..1e58b29a9a02c 100644 --- a/pandas/core/arrays/arrow/array.py +++ b/pandas/core/arrays/arrow/array.py @@ -12,6 +12,7 @@ cast, ) import unicodedata +import warnings import numpy as np @@ -28,6 +29,7 @@ pa_version_under13p0, ) from pandas.util._decorators import doc +from pandas.util._exceptions import find_stack_level from pandas.util._validators import validate_fillna_kwargs from pandas.core.dtypes.cast import ( @@ -663,20 +665,15 @@ def __array__( ) -> np.ndarray: """Correctly construct numpy arrays when passed to `np.asarray()`.""" if copy is False: - import warnings - - from pandas.util._exceptions import find_stack_level - warnings.warn( - "Numpy>=2.0 changed copy keyword's behavior, making copy=False" - "raise an error when a zero-copy numpy array is not possible", + "Starting on NumPy 2.0, the behavior of the 'copy' keyword has changed " + "and passing 'copy=False' raises an error when a zero-copy NumPy array " + "is not possible, Pandas will follow this behavior starting with " + "version 3.0. This conversion to NumPy requires a copy, but " + "'copy=False' was passed. Consider using 'np.asarray(..)' instead.", FutureWarning, stacklevel=find_stack_level(), ) - # TODO: By using `zero_copy_only` it may be possible to implement this - raise ValueError( - "Unable to avoid copy while creating an array as requested." - ) elif copy is None: # `to_numpy(copy=False)` has the meaning of NumPy `copy=None`. copy = False diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index 8e0932aa1ea72..1358fee128edf 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -1672,19 +1672,15 @@ def __array__( array(['a', 'b'], dtype=object) """ if copy is False: - import warnings - - from pandas.util._exceptions import find_stack_level - warnings.warn( - "Numpy>=2.0 changed copy keyword's behavior, making copy=False " - "raise an error when a zero-copy numpy array is not possible", + "Starting on NumPy 2.0, the behavior of the 'copy' keyword has changed " + "and passing 'copy=False' raises an error when a zero-copy NumPy array " + "is not possible, Pandas will follow this behavior starting with " + "version 3.0. This conversion to NumPy requires a copy, but " + "'copy=False' was passed. Consider using 'np.asarray(..)' instead.", FutureWarning, stacklevel=find_stack_level(), ) - raise ValueError( - "Unable to avoid copy while creating an array as requested." - ) ret = take_nd(self.categories._values, self._codes) # When we're a Categorical[ExtensionArray], like Interval, diff --git a/pandas/core/arrays/datetimelike.py b/pandas/core/arrays/datetimelike.py index 01ea5dd911f73..d88c9e98936b6 100644 --- a/pandas/core/arrays/datetimelike.py +++ b/pandas/core/arrays/datetimelike.py @@ -359,19 +359,17 @@ def __array__( # used for Timedelta/DatetimeArray, overwritten by PeriodArray if is_object_dtype(dtype): if copy is False: - import warnings - - from pandas.util._exceptions import find_stack_level - warnings.warn( - "Numpy>=2.0 changed copy keyword's behavior, making copy=False" - "raise an error when a zero-copy numpy array is not possible", + "Starting on NumPy 2.0, the behavior of the 'copy' keyword has " + "changed and passing 'copy=False' raises an error when a zero-copy " + "NumPy array is not possible, Pandas will follow this behavior " + "starting with version 3.0. This conversion to NumPy requires a " + "copy, but 'copy=False' was passed. Consider using " + "'np.asarray(..)' instead.", FutureWarning, stacklevel=find_stack_level(), ) - raise ValueError( - "Unable to avoid copy while creating an array as requested." - ) + return np.array(list(self), dtype=object) if copy is True: diff --git a/pandas/core/arrays/interval.py b/pandas/core/arrays/interval.py index 7fb86618b7447..1f55dbba6430f 100644 --- a/pandas/core/arrays/interval.py +++ b/pandas/core/arrays/interval.py @@ -42,6 +42,7 @@ from pandas.compat.numpy import function as nv from pandas.errors import IntCastingNaNError from pandas.util._decorators import Appender +from pandas.util._exceptions import find_stack_level from pandas.core.dtypes.cast import ( LossySetitemError, @@ -1575,19 +1576,15 @@ def __array__( objects (with dtype='object') """ if copy is False: - import warnings - - from pandas.util._exceptions import find_stack_level - warnings.warn( - "Numpy>=2.0 changed copy keyword's behavior, making copy=False" - "raise an error when a zero-copy numpy array is not possible", + "Starting on NumPy 2.0, the behavior of the 'copy' keyword has changed " + "and passing 'copy=False' raises an error when a zero-copy NumPy array " + "is not possible, Pandas will follow this behavior starting with " + "version 3.0. This conversion to NumPy requires a copy, but " + "'copy=False' was passed. Consider using 'np.asarray(..)' instead.", FutureWarning, stacklevel=find_stack_level(), ) - raise ValueError( - "Unable to avoid copy while creating an array as requested." - ) left = self._left right = self._right diff --git a/pandas/core/arrays/masked.py b/pandas/core/arrays/masked.py index 4935c649d62e9..fe945bae13137 100644 --- a/pandas/core/arrays/masked.py +++ b/pandas/core/arrays/masked.py @@ -38,6 +38,7 @@ ) from pandas.errors import AbstractMethodError from pandas.util._decorators import doc +from pandas.util._exceptions import find_stack_level from pandas.util._validators import validate_fillna_kwargs from pandas.core.dtypes.base import ExtensionDtype @@ -605,19 +606,15 @@ def __array__( # special case, here we can simply return the underlying data return np.array(self._data, dtype=dtype, copy=copy) - import warnings - - from pandas.util._exceptions import find_stack_level - warnings.warn( - "Numpy>=2.0 changed copy keyword's behavior, making copy=False" - "raise an error when a zero-copy numpy array is not possible", + "Starting on NumPy 2.0, the behavior of the 'copy' keyword has changed " + "and passing 'copy=False' raises an error when a zero-copy NumPy array " + "is not possible, Pandas will follow this behavior starting with " + "version 3.0. This conversion to NumPy requires a copy, but " + "'copy=False' was passed. Consider using 'np.asarray(..)' instead.", FutureWarning, stacklevel=find_stack_level(), ) - raise ValueError( - "Unable to avoid copy while creating an array as requested." - ) if copy is None: copy = False # The NumPy copy=False meaning is different here. diff --git a/pandas/core/arrays/period.py b/pandas/core/arrays/period.py index 9326358d1eaa7..8570ae1b1f3f4 100644 --- a/pandas/core/arrays/period.py +++ b/pandas/core/arrays/period.py @@ -415,19 +415,15 @@ def __array__( return np.array(self.asi8, dtype=dtype) if copy is False: - import warnings - - from pandas.util._exceptions import find_stack_level - warnings.warn( - "Numpy>=2.0 changed copy keyword's behavior, making copy=False" - "raise an error when a zero-copy numpy array is not possible", + "Starting on NumPy 2.0, the behavior of the 'copy' keyword has changed " + "and passing 'copy=False' raises an error when a zero-copy NumPy array " + "is not possible, Pandas will follow this behavior starting with " + "version 3.0. This conversion to NumPy requires a copy, but " + "'copy=False' was passed. Consider using 'np.asarray(..)' instead.", FutureWarning, stacklevel=find_stack_level(), ) - raise ValueError( - "Unable to avoid copy while creating an array as requested." - ) if dtype == bool: return ~self._isnan diff --git a/pandas/core/arrays/sparse/array.py b/pandas/core/arrays/sparse/array.py index 53c577fde7e65..662ee3609833f 100644 --- a/pandas/core/arrays/sparse/array.py +++ b/pandas/core/arrays/sparse/array.py @@ -562,19 +562,15 @@ def __array__( return self.sp_values if copy is False: - import warnings - - from pandas.util._exceptions import find_stack_level - warnings.warn( - "Numpy>=2.0 changed copy keyword's behavior, making copy=False" - "raise an error when a zero-copy numpy array is not possible", + "Starting on NumPy 2.0, the behavior of the 'copy' keyword has changed " + "and passing 'copy=False' raises an error when a zero-copy NumPy array " + "is not possible, Pandas will follow this behavior starting with " + "version 3.0. This conversion to NumPy requires a copy, but " + "'copy=False' was passed. Consider using 'np.asarray(..)' instead.", FutureWarning, stacklevel=find_stack_level(), ) - raise ValueError( - "Unable to avoid copy while creating an array as requested." - ) fill_value = self.fill_value diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 65b76962a7932..1d9ecfc51d544 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2151,20 +2151,16 @@ def __array__( ) -> np.ndarray: if copy is False and not self._mgr.is_single_block and not self.empty: # check this manually, otherwise ._values will already return a copy - # and np.array(values, copy=False) will not raise an error - import warnings - - from pandas.util._exceptions import find_stack_level - + # and np.array(values, copy=False) will not raise a warning warnings.warn( - "Numpy>=2.0 changed the copy keyword behavior, making copy=False" - "raise an error when a zero-copy numpy array is not possible.", + "Starting on NumPy 2.0, the behavior of the 'copy' keyword has changed " + "and passing 'copy=False' raises an error when a zero-copy NumPy array " + "is not possible, Pandas will follow this behavior starting with " + "version 3.0. This conversion to NumPy requires a copy, but " + "'copy=False' was passed. Consider using 'np.asarray(..)' instead.", FutureWarning, stacklevel=find_stack_level(), ) - raise ValueError( - "Unable to avoid copy while creating an array as requested." - ) values = self._values if copy is None: # Note: branch avoids `copy=None` for NumPy 1.x support diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index 3cd04450e0144..31d56d2d1627c 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -1314,19 +1314,15 @@ def __array__(self, dtype=None, copy=None) -> np.ndarray: """the array interface, return my values""" if copy is False: # self.values is always a newly construct array, so raise. - import warnings - - from pandas.util._exceptions import find_stack_level - warnings.warn( - "Numpy>=2.0 changed copy keyword's behavior, making copy=False" - "raise an error when a zero-copy numpy array is not possible", + "Starting on NumPy 2.0, the behavior of the 'copy' keyword has changed " + "and passing 'copy=False' raises an error when a zero-copy NumPy array " + "is not possible, Pandas will follow this behavior starting with " + "version 3.0. This conversion to NumPy requires a copy, but " + "'copy=False' was passed. Consider using 'np.asarray(..)' instead.", FutureWarning, stacklevel=find_stack_level(), ) - raise ValueError( - "Unable to avoid copy while creating an array as requested." - ) if copy is True: # explicit np.array call to ensure a copy is made and unique objects # are returned, because self.values is cached From ac0573c025c192d4f7c13dc5502f773c18534923 Mon Sep 17 00:00:00 2001 From: KevsterAmp Date: Mon, 25 Nov 2024 19:28:45 +0800 Subject: [PATCH 03/13] raise warning on JSON __array__ --- pandas/tests/extension/json/array.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pandas/tests/extension/json/array.py b/pandas/tests/extension/json/array.py index b6d72c10712f2..51a9942cb9efc 100644 --- a/pandas/tests/extension/json/array.py +++ b/pandas/tests/extension/json/array.py @@ -25,9 +25,12 @@ TYPE_CHECKING, Any, ) +import warnings import numpy as np +from pandas.util._exceptions import find_stack_level + from pandas.core.dtypes.cast import construct_1d_object_array_from_listlike from pandas.core.dtypes.common import ( is_bool_dtype, @@ -148,8 +151,14 @@ def __ne__(self, other): def __array__(self, dtype=None, copy=None): if copy is False: - raise ValueError( - "Unable to avoid copy while creating an array as requested." + warnings.warn( + "Starting on NumPy 2.0, the behavior of the 'copy' keyword has changed " + "and passing 'copy=False' raises an error when a zero-copy NumPy array " + "is not possible, Pandas will follow this behavior starting with " + "version 3.0. This conversion to NumPy requires a copy, but " + "'copy=False' was passed. Consider using 'np.asarray(..)' instead.", + FutureWarning, + stacklevel=find_stack_level(), ) if dtype is None: From 504a4840588a22083dfc7e139b45a27aedb6cc02 Mon Sep 17 00:00:00 2001 From: KevsterAmp Date: Tue, 26 Nov 2024 18:56:30 +0800 Subject: [PATCH 04/13] modify tests relating to __array__ and assert FutureWarning --- pandas/tests/arrays/sparse/test_array.py | 8 ++++++-- pandas/tests/base/test_conversion.py | 8 ++++++-- pandas/tests/extension/base/interface.py | 10 ++++++---- pandas/tests/indexes/multi/test_conversion.py | 7 ++++++- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/pandas/tests/arrays/sparse/test_array.py b/pandas/tests/arrays/sparse/test_array.py index 1e8d36b184e48..310283538fe16 100644 --- a/pandas/tests/arrays/sparse/test_array.py +++ b/pandas/tests/arrays/sparse/test_array.py @@ -500,8 +500,12 @@ def test_array_interface(arr_data, arr): # copy=False semantics are only supported in NumPy>=2. return - # for sparse arrays, copy=False is never allowed - with pytest.raises(ValueError, match="Unable to avoid copy while creating"): + msg = "Starting on NumPy 2.0, the behavior of the 'copy' keyword has changed " + "and passing 'copy=False' raises an error when a zero-copy NumPy array " + "is not possible, Pandas will follow this behavior starting with " + "version 3.0. This conversion to NumPy requires a copy, but " + "'copy=False' was passed. Consider using 'np.asarray(..)' instead." + with tm.assert_produces_warning(FutureWarning, match=msg): np.array(arr, copy=False) # except when there are actually no sparse filled values diff --git a/pandas/tests/base/test_conversion.py b/pandas/tests/base/test_conversion.py index e2bf19e2e736c..c9280c887eab8 100644 --- a/pandas/tests/base/test_conversion.py +++ b/pandas/tests/base/test_conversion.py @@ -380,8 +380,12 @@ def test_to_numpy(arr, expected, zero_copy, index_or_series_or_array): return if not zero_copy: - with pytest.raises(ValueError, match="Unable to avoid copy while creating"): - # An error is always acceptable for `copy=False` + msg = "Starting on NumPy 2.0, the behavior of the 'copy' keyword has changed " + "and passing 'copy=False' raises an error when a zero-copy NumPy array " + "is not possible, Pandas will follow this behavior starting with " + "version 3.0. This conversion to NumPy requires a copy, but " + "'copy=False' was passed. Consider using 'np.asarray(..)' instead." + with tm.assert_produces_warning(FutureWarning, match=msg): np.array(thing, copy=False) else: diff --git a/pandas/tests/extension/base/interface.py b/pandas/tests/extension/base/interface.py index 79eb64b5a654f..b786df0f84105 100644 --- a/pandas/tests/extension/base/interface.py +++ b/pandas/tests/extension/base/interface.py @@ -82,11 +82,13 @@ def test_array_interface_copy(self, data): # copy=False semantics are only supported in NumPy>=2. return - try: + msg = "Starting on NumPy 2.0, the behavior of the 'copy' keyword has changed " + "and passing 'copy=False' raises an error when a zero-copy NumPy array " + "is not possible, Pandas will follow this behavior starting with " + "version 3.0. This conversion to NumPy requires a copy, but " + "'copy=False' was passed. Consider using 'np.asarray(..)' instead." + with tm.assert_produces_warning(FutureWarning, match=msg): result_nocopy1 = np.array(data, copy=False) - except ValueError: - # An error is always acceptable for `copy=False` - return result_nocopy2 = np.array(data, copy=False) # If copy=False was given and did not raise, these must share the same data diff --git a/pandas/tests/indexes/multi/test_conversion.py b/pandas/tests/indexes/multi/test_conversion.py index 58a2dc00f937d..5a9b3980086d1 100644 --- a/pandas/tests/indexes/multi/test_conversion.py +++ b/pandas/tests/indexes/multi/test_conversion.py @@ -47,7 +47,12 @@ def test_array_interface(idx): return # for MultiIndex, copy=False is never allowed - with pytest.raises(ValueError, match="Unable to avoid copy while creating"): + msg = "Starting on NumPy 2.0, the behavior of the 'copy' keyword has changed " + "and passing 'copy=False' raises an error when a zero-copy NumPy array " + "is not possible, Pandas will follow this behavior starting with " + "version 3.0. This conversion to NumPy requires a copy, but " + "'copy=False' was passed. Consider using 'np.asarray(..)' instead." + with tm.assert_produces_warning(FutureWarning, match=msg): np.array(idx, copy=False) From 8574f977768d6628739993254d22af65bcdea92f Mon Sep 17 00:00:00 2001 From: KevsterAmp Date: Tue, 26 Nov 2024 19:11:39 +0800 Subject: [PATCH 05/13] modify whatsnew doc --- doc/source/whatsnew/v2.3.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v2.3.0.rst b/doc/source/whatsnew/v2.3.0.rst index 473d67acf6e74..7ccafbb4cf1df 100644 --- a/doc/source/whatsnew/v2.3.0.rst +++ b/doc/source/whatsnew/v2.3.0.rst @@ -34,7 +34,7 @@ Other enhancements - The semantics for the ``copy`` keyword in ``__array__`` methods (i.e. called when using ``np.array()`` or ``np.asarray()`` on pandas objects) has been - updated to work correctly with NumPy >= 2 (:issue:`57739`) + updated to raise FutureWarning with NumPy >= 2 (:issue:`60340`) - The :meth:`~Series.sum` reduction is now implemented for ``StringDtype`` columns (:issue:`59853`) - From fab1f17088dd2f63a44884887ab03606870446e5 Mon Sep 17 00:00:00 2001 From: Kevin Amparado <109636487+KevsterAmp@users.noreply.github.com> Date: Thu, 5 Dec 2024 20:07:55 +0800 Subject: [PATCH 06/13] Update pandas/core/arrays/arrow/array.py warning msg Co-authored-by: Joris Van den Bossche --- pandas/core/arrays/arrow/array.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/arrays/arrow/array.py b/pandas/core/arrays/arrow/array.py index 1e58b29a9a02c..eabbff34bd7c8 100644 --- a/pandas/core/arrays/arrow/array.py +++ b/pandas/core/arrays/arrow/array.py @@ -666,10 +666,10 @@ def __array__( """Correctly construct numpy arrays when passed to `np.asarray()`.""" if copy is False: warnings.warn( - "Starting on NumPy 2.0, the behavior of the 'copy' keyword has changed " - "and passing 'copy=False' raises an error when a zero-copy NumPy array " - "is not possible, Pandas will follow this behavior starting with " - "version 3.0. This conversion to NumPy requires a copy, but " + "Starting with NumPy 2.0, the behavior of the 'copy' keyword has changed " + "and passing 'copy=False' raises an error when returning a zero-copy NumPy array " + "is not possible. pandas will follow this behavior starting with " + "pandas 3.0.\nThis conversion to NumPy requires a copy, but " "'copy=False' was passed. Consider using 'np.asarray(..)' instead.", FutureWarning, stacklevel=find_stack_level(), From f419a918f91df6078095759fbfad0fde1b229a72 Mon Sep 17 00:00:00 2001 From: KevsterAmp Date: Thu, 19 Dec 2024 19:18:39 +0800 Subject: [PATCH 07/13] update warning msg on all __array__ --- pandas/core/arrays/categorical.py | 11 ++++++----- pandas/core/arrays/datetimelike.py | 10 +++++----- pandas/core/arrays/interval.py | 11 ++++++----- pandas/core/arrays/masked.py | 11 ++++++----- pandas/core/arrays/period.py | 11 ++++++----- pandas/core/arrays/sparse/array.py | 11 ++++++----- pandas/core/generic.py | 11 ++++++----- pandas/core/indexes/multi.py | 11 ++++++----- 8 files changed, 47 insertions(+), 40 deletions(-) diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index 1358fee128edf..0fe69f6d1ebc2 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -1673,11 +1673,12 @@ def __array__( """ if copy is False: warnings.warn( - "Starting on NumPy 2.0, the behavior of the 'copy' keyword has changed " - "and passing 'copy=False' raises an error when a zero-copy NumPy array " - "is not possible, Pandas will follow this behavior starting with " - "version 3.0. This conversion to NumPy requires a copy, but " - "'copy=False' was passed. Consider using 'np.asarray(..)' instead.", + "Starting with NumPy 2.0, the behavior of the 'copy' keyword has " + "changed and passing 'copy=False' raises an error when returning " + "a zero-copy NumPy array is not possible. pandas will follow " + "this behavior starting with pandas 3.0.\nThis conversion to " + "NumPy requires a copy, but 'copy=False' was passed. Consider " + "using 'np.asarray(..)' instead.", FutureWarning, stacklevel=find_stack_level(), ) diff --git a/pandas/core/arrays/datetimelike.py b/pandas/core/arrays/datetimelike.py index d88c9e98936b6..cfe1f3acd9143 100644 --- a/pandas/core/arrays/datetimelike.py +++ b/pandas/core/arrays/datetimelike.py @@ -360,11 +360,11 @@ def __array__( if is_object_dtype(dtype): if copy is False: warnings.warn( - "Starting on NumPy 2.0, the behavior of the 'copy' keyword has " - "changed and passing 'copy=False' raises an error when a zero-copy " - "NumPy array is not possible, Pandas will follow this behavior " - "starting with version 3.0. This conversion to NumPy requires a " - "copy, but 'copy=False' was passed. Consider using " + "Starting with NumPy 2.0, the behavior of the 'copy' keyword has " + "changed and passing 'copy=False' raises an error when returning " + "a zero-copy NumPy array is not possible. pandas will follow this " + "behavior starting with pandas 3.0.\nThis conversion to NumPy " + "requires a copy, but 'copy=False' was passed. Consider using " "'np.asarray(..)' instead.", FutureWarning, stacklevel=find_stack_level(), diff --git a/pandas/core/arrays/interval.py b/pandas/core/arrays/interval.py index 1f55dbba6430f..da57e4ceed87e 100644 --- a/pandas/core/arrays/interval.py +++ b/pandas/core/arrays/interval.py @@ -1577,11 +1577,12 @@ def __array__( """ if copy is False: warnings.warn( - "Starting on NumPy 2.0, the behavior of the 'copy' keyword has changed " - "and passing 'copy=False' raises an error when a zero-copy NumPy array " - "is not possible, Pandas will follow this behavior starting with " - "version 3.0. This conversion to NumPy requires a copy, but " - "'copy=False' was passed. Consider using 'np.asarray(..)' instead.", + "Starting with NumPy 2.0, the behavior of the 'copy' keyword has " + "changed and passing 'copy=False' raises an error when returning " + "a zero-copy NumPy array is not possible. pandas will follow " + "this behavior starting with pandas 3.0.\nThis conversion to " + "NumPy requires a copy, but 'copy=False' was passed. Consider " + "using 'np.asarray(..)' instead.", FutureWarning, stacklevel=find_stack_level(), ) diff --git a/pandas/core/arrays/masked.py b/pandas/core/arrays/masked.py index fe945bae13137..da656a2768901 100644 --- a/pandas/core/arrays/masked.py +++ b/pandas/core/arrays/masked.py @@ -607,11 +607,12 @@ def __array__( return np.array(self._data, dtype=dtype, copy=copy) warnings.warn( - "Starting on NumPy 2.0, the behavior of the 'copy' keyword has changed " - "and passing 'copy=False' raises an error when a zero-copy NumPy array " - "is not possible, Pandas will follow this behavior starting with " - "version 3.0. This conversion to NumPy requires a copy, but " - "'copy=False' was passed. Consider using 'np.asarray(..)' instead.", + "Starting with NumPy 2.0, the behavior of the 'copy' keyword has " + "changed and passing 'copy=False' raises an error when returning " + "a zero-copy NumPy array is not possible. pandas will follow " + "this behavior starting with pandas 3.0.\nThis conversion to " + "NumPy requires a copy, but 'copy=False' was passed. Consider " + "using 'np.asarray(..)' instead.", FutureWarning, stacklevel=find_stack_level(), ) diff --git a/pandas/core/arrays/period.py b/pandas/core/arrays/period.py index 8570ae1b1f3f4..2947ba7b8c72a 100644 --- a/pandas/core/arrays/period.py +++ b/pandas/core/arrays/period.py @@ -416,11 +416,12 @@ def __array__( if copy is False: warnings.warn( - "Starting on NumPy 2.0, the behavior of the 'copy' keyword has changed " - "and passing 'copy=False' raises an error when a zero-copy NumPy array " - "is not possible, Pandas will follow this behavior starting with " - "version 3.0. This conversion to NumPy requires a copy, but " - "'copy=False' was passed. Consider using 'np.asarray(..)' instead.", + "Starting with NumPy 2.0, the behavior of the 'copy' keyword has " + "changed and passing 'copy=False' raises an error when returning " + "a zero-copy NumPy array is not possible. pandas will follow " + "this behavior starting with pandas 3.0.\nThis conversion to " + "NumPy requires a copy, but 'copy=False' was passed. Consider " + "using 'np.asarray(..)' instead.", FutureWarning, stacklevel=find_stack_level(), ) diff --git a/pandas/core/arrays/sparse/array.py b/pandas/core/arrays/sparse/array.py index 662ee3609833f..07ff592f491a8 100644 --- a/pandas/core/arrays/sparse/array.py +++ b/pandas/core/arrays/sparse/array.py @@ -563,11 +563,12 @@ def __array__( if copy is False: warnings.warn( - "Starting on NumPy 2.0, the behavior of the 'copy' keyword has changed " - "and passing 'copy=False' raises an error when a zero-copy NumPy array " - "is not possible, Pandas will follow this behavior starting with " - "version 3.0. This conversion to NumPy requires a copy, but " - "'copy=False' was passed. Consider using 'np.asarray(..)' instead.", + "Starting with NumPy 2.0, the behavior of the 'copy' keyword has " + "changed and passing 'copy=False' raises an error when returning " + "a zero-copy NumPy array is not possible. pandas will follow " + "this behavior starting with pandas 3.0.\nThis conversion to " + "NumPy requires a copy, but 'copy=False' was passed. Consider " + "using 'np.asarray(..)' instead.", FutureWarning, stacklevel=find_stack_level(), ) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 1d9ecfc51d544..70b72577dd5d1 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2153,11 +2153,12 @@ def __array__( # check this manually, otherwise ._values will already return a copy # and np.array(values, copy=False) will not raise a warning warnings.warn( - "Starting on NumPy 2.0, the behavior of the 'copy' keyword has changed " - "and passing 'copy=False' raises an error when a zero-copy NumPy array " - "is not possible, Pandas will follow this behavior starting with " - "version 3.0. This conversion to NumPy requires a copy, but " - "'copy=False' was passed. Consider using 'np.asarray(..)' instead.", + "Starting with NumPy 2.0, the behavior of the 'copy' keyword has " + "changed and passing 'copy=False' raises an error when returning " + "a zero-copy NumPy array is not possible. pandas will follow " + "this behavior starting with pandas 3.0.\nThis conversion to " + "NumPy requires a copy, but 'copy=False' was passed. Consider " + "using 'np.asarray(..)' instead.", FutureWarning, stacklevel=find_stack_level(), ) diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index 31d56d2d1627c..8954d49649a2b 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -1315,11 +1315,12 @@ def __array__(self, dtype=None, copy=None) -> np.ndarray: if copy is False: # self.values is always a newly construct array, so raise. warnings.warn( - "Starting on NumPy 2.0, the behavior of the 'copy' keyword has changed " - "and passing 'copy=False' raises an error when a zero-copy NumPy array " - "is not possible, Pandas will follow this behavior starting with " - "version 3.0. This conversion to NumPy requires a copy, but " - "'copy=False' was passed. Consider using 'np.asarray(..)' instead.", + "Starting with NumPy 2.0, the behavior of the 'copy' keyword has " + "changed and passing 'copy=False' raises an error when returning " + "a zero-copy NumPy array is not possible. pandas will follow " + "this behavior starting with pandas 3.0.\nThis conversion to " + "NumPy requires a copy, but 'copy=False' was passed. Consider " + "using 'np.asarray(..)' instead.", FutureWarning, stacklevel=find_stack_level(), ) From ce83e09e42666b08f1c166a5d2273484225a9f03 Mon Sep 17 00:00:00 2001 From: KevsterAmp Date: Thu, 19 Dec 2024 19:37:22 +0800 Subject: [PATCH 08/13] replace warning msg on tests/extension/json/array.py --- pandas/tests/extension/json/array.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pandas/tests/extension/json/array.py b/pandas/tests/extension/json/array.py index 51a9942cb9efc..5ff99589a1961 100644 --- a/pandas/tests/extension/json/array.py +++ b/pandas/tests/extension/json/array.py @@ -152,11 +152,12 @@ def __ne__(self, other): def __array__(self, dtype=None, copy=None): if copy is False: warnings.warn( - "Starting on NumPy 2.0, the behavior of the 'copy' keyword has changed " - "and passing 'copy=False' raises an error when a zero-copy NumPy array " - "is not possible, Pandas will follow this behavior starting with " - "version 3.0. This conversion to NumPy requires a copy, but " - "'copy=False' was passed. Consider using 'np.asarray(..)' instead.", + "Starting with NumPy 2.0, the behavior of the 'copy' keyword has " + "changed and passing 'copy=False' raises an error when returning " + "a zero-copy NumPy array is not possible. pandas will follow " + "this behavior starting with pandas 3.0.\nThis conversion to " + "NumPy requires a copy, but 'copy=False' was passed. Consider " + "using 'np.asarray(..)' instead.", FutureWarning, stacklevel=find_stack_level(), ) From 1820f78d18236113b59da2d534651dd0e9354ca9 Mon Sep 17 00:00:00 2001 From: KevsterAmp Date: Thu, 19 Dec 2024 19:37:54 +0800 Subject: [PATCH 09/13] replace msg with first part instead of the whole --- pandas/tests/arrays/sparse/test_array.py | 6 +----- pandas/tests/base/test_conversion.py | 6 +----- pandas/tests/extension/base/interface.py | 6 +----- pandas/tests/indexes/multi/test_conversion.py | 6 +----- 4 files changed, 4 insertions(+), 20 deletions(-) diff --git a/pandas/tests/arrays/sparse/test_array.py b/pandas/tests/arrays/sparse/test_array.py index 310283538fe16..b2a570b14df3c 100644 --- a/pandas/tests/arrays/sparse/test_array.py +++ b/pandas/tests/arrays/sparse/test_array.py @@ -500,11 +500,7 @@ def test_array_interface(arr_data, arr): # copy=False semantics are only supported in NumPy>=2. return - msg = "Starting on NumPy 2.0, the behavior of the 'copy' keyword has changed " - "and passing 'copy=False' raises an error when a zero-copy NumPy array " - "is not possible, Pandas will follow this behavior starting with " - "version 3.0. This conversion to NumPy requires a copy, but " - "'copy=False' was passed. Consider using 'np.asarray(..)' instead." + msg = "Starting with NumPy 2.0, the behavior of the 'copy' keyword has changed" with tm.assert_produces_warning(FutureWarning, match=msg): np.array(arr, copy=False) diff --git a/pandas/tests/base/test_conversion.py b/pandas/tests/base/test_conversion.py index c9280c887eab8..b80ac060fc194 100644 --- a/pandas/tests/base/test_conversion.py +++ b/pandas/tests/base/test_conversion.py @@ -380,11 +380,7 @@ def test_to_numpy(arr, expected, zero_copy, index_or_series_or_array): return if not zero_copy: - msg = "Starting on NumPy 2.0, the behavior of the 'copy' keyword has changed " - "and passing 'copy=False' raises an error when a zero-copy NumPy array " - "is not possible, Pandas will follow this behavior starting with " - "version 3.0. This conversion to NumPy requires a copy, but " - "'copy=False' was passed. Consider using 'np.asarray(..)' instead." + msg = "Starting with NumPy 2.0, the behavior of the 'copy' keyword has changed" with tm.assert_produces_warning(FutureWarning, match=msg): np.array(thing, copy=False) diff --git a/pandas/tests/extension/base/interface.py b/pandas/tests/extension/base/interface.py index b786df0f84105..69468e984fc6e 100644 --- a/pandas/tests/extension/base/interface.py +++ b/pandas/tests/extension/base/interface.py @@ -82,11 +82,7 @@ def test_array_interface_copy(self, data): # copy=False semantics are only supported in NumPy>=2. return - msg = "Starting on NumPy 2.0, the behavior of the 'copy' keyword has changed " - "and passing 'copy=False' raises an error when a zero-copy NumPy array " - "is not possible, Pandas will follow this behavior starting with " - "version 3.0. This conversion to NumPy requires a copy, but " - "'copy=False' was passed. Consider using 'np.asarray(..)' instead." + msg = "Starting with NumPy 2.0, the behavior of the 'copy' keyword has changed" with tm.assert_produces_warning(FutureWarning, match=msg): result_nocopy1 = np.array(data, copy=False) diff --git a/pandas/tests/indexes/multi/test_conversion.py b/pandas/tests/indexes/multi/test_conversion.py index 5a9b3980086d1..d62bd5438a1e3 100644 --- a/pandas/tests/indexes/multi/test_conversion.py +++ b/pandas/tests/indexes/multi/test_conversion.py @@ -47,11 +47,7 @@ def test_array_interface(idx): return # for MultiIndex, copy=False is never allowed - msg = "Starting on NumPy 2.0, the behavior of the 'copy' keyword has changed " - "and passing 'copy=False' raises an error when a zero-copy NumPy array " - "is not possible, Pandas will follow this behavior starting with " - "version 3.0. This conversion to NumPy requires a copy, but " - "'copy=False' was passed. Consider using 'np.asarray(..)' instead." + msg = "Starting with NumPy 2.0, the behavior of the 'copy' keyword has changed" with tm.assert_produces_warning(FutureWarning, match=msg): np.array(idx, copy=False) From d466e24f67fad080471a294479e581ad734e823d Mon Sep 17 00:00:00 2001 From: KevsterAmp Date: Thu, 19 Dec 2024 19:41:18 +0800 Subject: [PATCH 10/13] replace ValueError assertion with FutureWarning when copy=False --- pandas/tests/copy_view/test_array.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/tests/copy_view/test_array.py b/pandas/tests/copy_view/test_array.py index 06d9424450011..0dabec6014b0d 100644 --- a/pandas/tests/copy_view/test_array.py +++ b/pandas/tests/copy_view/test_array.py @@ -187,7 +187,8 @@ def test_dataframe_multiple_numpy_dtypes(): if np_version_gt2: # copy=False semantics are only supported in NumPy>=2. - with pytest.raises(ValueError, match="Unable to avoid copy while creating"): + msg = "Starting with NumPy 2.0, the behavior of the 'copy' keyword has changed" + with pytest.raises(FutureWarning, match=msg): arr = np.array(df, copy=False) arr = np.array(df, copy=True) From 9786ee3546f312cee8e5f3c970ee5ad74a44f9cd Mon Sep 17 00:00:00 2001 From: KevsterAmp Date: Thu, 19 Dec 2024 19:54:29 +0800 Subject: [PATCH 11/13] fix codecheck errors --- pandas/core/arrays/arrow/array.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pandas/core/arrays/arrow/array.py b/pandas/core/arrays/arrow/array.py index eabbff34bd7c8..16dfa7e051d0d 100644 --- a/pandas/core/arrays/arrow/array.py +++ b/pandas/core/arrays/arrow/array.py @@ -666,11 +666,12 @@ def __array__( """Correctly construct numpy arrays when passed to `np.asarray()`.""" if copy is False: warnings.warn( - "Starting with NumPy 2.0, the behavior of the 'copy' keyword has changed " - "and passing 'copy=False' raises an error when returning a zero-copy NumPy array " - "is not possible. pandas will follow this behavior starting with " - "pandas 3.0.\nThis conversion to NumPy requires a copy, but " - "'copy=False' was passed. Consider using 'np.asarray(..)' instead.", + "Starting with NumPy 2.0, the behavior of the 'copy' keyword has " + "changed and passing 'copy=False' raises an error when returning " + "a zero-copy NumPy array is not possible. pandas will follow " + "this behavior starting with pandas 3.0.\nThis conversion to " + "NumPy requires a copy, but 'copy=False' was passed. Consider " + "using 'np.asarray(..)' instead.", FutureWarning, stacklevel=find_stack_level(), ) From f9fc8e897035259e56da5f121d8f51735d5d66fc Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Fri, 3 Jan 2025 14:45:07 +0100 Subject: [PATCH 12/13] fix base extension test --- pandas/tests/extension/base/interface.py | 26 +++++++++++++++---- .../tests/extension/decimal/test_decimal.py | 20 ++++++++++++++ 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/pandas/tests/extension/base/interface.py b/pandas/tests/extension/base/interface.py index 69468e984fc6e..38cece7da3308 100644 --- a/pandas/tests/extension/base/interface.py +++ b/pandas/tests/extension/base/interface.py @@ -1,3 +1,5 @@ +import warnings + import numpy as np import pytest @@ -82,13 +84,27 @@ def test_array_interface_copy(self, data): # copy=False semantics are only supported in NumPy>=2. return + warning_raised = False msg = "Starting with NumPy 2.0, the behavior of the 'copy' keyword has changed" - with tm.assert_produces_warning(FutureWarning, match=msg): + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter("always") result_nocopy1 = np.array(data, copy=False) - - result_nocopy2 = np.array(data, copy=False) - # If copy=False was given and did not raise, these must share the same data - assert np.may_share_memory(result_nocopy1, result_nocopy2) + assert len(w) <= 1 + if len(w): + warning_raised = True + assert msg in str(w[0].message) + + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter("always") + result_nocopy2 = np.array(data, copy=False) + assert len(w) <= 1 + if len(w): + warning_raised = True + assert msg in str(w[0].message) + + if not warning_raised: + # If copy=False was given and did not raise, these must share the same data + assert np.may_share_memory(result_nocopy1, result_nocopy2) def test_is_extension_array_dtype(self, data): assert is_extension_array_dtype(data) diff --git a/pandas/tests/extension/decimal/test_decimal.py b/pandas/tests/extension/decimal/test_decimal.py index 8afb989508e04..8590cd7fdc235 100644 --- a/pandas/tests/extension/decimal/test_decimal.py +++ b/pandas/tests/extension/decimal/test_decimal.py @@ -6,6 +6,8 @@ import numpy as np import pytest +from pandas.compat.numpy import np_version_gt2 + import pandas as pd import pandas._testing as tm from pandas.tests.extension import base @@ -289,6 +291,24 @@ def test_series_repr(self, data): def test_unary_ufunc_dunder_equivalence(self, data, ufunc): super().test_unary_ufunc_dunder_equivalence(data, ufunc) + def test_array_interface_copy(self, data): + result_copy1 = np.array(data, copy=True) + result_copy2 = np.array(data, copy=True) + assert not np.may_share_memory(result_copy1, result_copy2) + if not np_version_gt2: + # copy=False semantics are only supported in NumPy>=2. + return + + try: + result_nocopy1 = np.array(data, copy=False) + except ValueError: + # An error is always acceptable for `copy=False` + return + + result_nocopy2 = np.array(data, copy=False) + # If copy=False was given and did not raise, these must share the same data + assert np.may_share_memory(result_nocopy1, result_nocopy2) + def test_take_na_value_other_decimal(): arr = DecimalArray([decimal.Decimal("1.0"), decimal.Decimal("2.0")]) From 60c527483392c84edf30bbc3cec60485fc083c64 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Fri, 3 Jan 2025 21:44:50 +0100 Subject: [PATCH 13/13] remove xfail --- pandas/tests/io/test_fsspec.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pandas/tests/io/test_fsspec.py b/pandas/tests/io/test_fsspec.py index cf59e3e4c4934..e0d652facb8fc 100644 --- a/pandas/tests/io/test_fsspec.py +++ b/pandas/tests/io/test_fsspec.py @@ -5,8 +5,6 @@ from pandas._config import using_string_dtype -from pandas.compat import HAS_PYARROW - from pandas import ( DataFrame, date_range, @@ -170,9 +168,6 @@ def test_excel_options(fsspectest): assert fsspectest.test[0] == "read" -@pytest.mark.xfail( - using_string_dtype() and HAS_PYARROW, reason="TODO(infer_string) fastparquet" -) def test_to_parquet_new_file(cleared_fs, df1): """Regression test for writing to a not-yet-existent GCS Parquet file.""" pytest.importorskip("fastparquet")