|
12 | 12 | cast, |
13 | 13 | ) |
14 | 14 | import unicodedata |
| 15 | +import warnings |
15 | 16 |
|
16 | 17 | import numpy as np |
17 | 18 |
|
|
28 | 29 | pa_version_under13p0, |
29 | 30 | ) |
30 | 31 | from pandas.util._decorators import doc |
| 32 | +from pandas.util._exceptions import find_stack_level |
31 | 33 | from pandas.util._validators import validate_fillna_kwargs |
32 | 34 |
|
33 | 35 | from pandas.core.dtypes.cast import ( |
@@ -663,9 +665,15 @@ def __array__( |
663 | 665 | ) -> np.ndarray: |
664 | 666 | """Correctly construct numpy arrays when passed to `np.asarray()`.""" |
665 | 667 | if copy is False: |
666 | | - # TODO: By using `zero_copy_only` it may be possible to implement this |
667 | | - raise ValueError( |
668 | | - "Unable to avoid copy while creating an array as requested." |
| 668 | + warnings.warn( |
| 669 | + "Starting with NumPy 2.0, the behavior of the 'copy' keyword has " |
| 670 | + "changed and passing 'copy=False' raises an error when returning " |
| 671 | + "a zero-copy NumPy array is not possible. pandas will follow " |
| 672 | + "this behavior starting with pandas 3.0.\nThis conversion to " |
| 673 | + "NumPy requires a copy, but 'copy=False' was passed. Consider " |
| 674 | + "using 'np.asarray(..)' instead.", |
| 675 | + FutureWarning, |
| 676 | + stacklevel=find_stack_level(), |
669 | 677 | ) |
670 | 678 | elif copy is None: |
671 | 679 | # `to_numpy(copy=False)` has the meaning of NumPy `copy=None`. |
@@ -2150,6 +2158,9 @@ def interpolate( |
2150 | 2158 | See NDFrame.interpolate.__doc__. |
2151 | 2159 | """ |
2152 | 2160 | # NB: we return type(self) even if copy=False |
| 2161 | + if not self.dtype._is_numeric: |
| 2162 | + raise TypeError(f"Cannot interpolate with {self.dtype} dtype") |
| 2163 | + |
2153 | 2164 | mask = self.isna() |
2154 | 2165 | if self.dtype.kind == "f": |
2155 | 2166 | data = self._pa_array.to_numpy() |
|
0 commit comments