From 6f4c0fc1a0ae380107396264777e9b2b246a57ad Mon Sep 17 00:00:00 2001 From: Ryan Nazareth Date: Thu, 2 Jan 2020 04:27:12 +0000 Subject: [PATCH] deprecate is_copy argument of take and remove is_copy=False usage --- pandas/core/generic.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 85bbf9b553b0a..3414e345c1a9b 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -3259,7 +3259,7 @@ def _clear_item_cache(self) -> None: # ---------------------------------------------------------------------- # Indexing Methods - def take(self, indices, axis=0, is_copy: bool_t = True, **kwargs): + def take(self, indices, axis=0, is_copy: bool_t = None, **kwargs): """ Return the elements in the given *positional* indices along an axis. @@ -3276,6 +3276,8 @@ def take(self, indices, axis=0, is_copy: bool_t = True, **kwargs): selecting rows, ``1`` means that we are selecting columns. is_copy : bool, default True Whether to return a copy of the original object or not. + + .. deprecated:: 1.0.0 **kwargs For compatibility with :meth:`numpy.take`. Has no effect on the output. @@ -3344,9 +3346,17 @@ class max_speed result = self._constructor(new_data).__finalize__(self) # Maybe set copy if we didn't actually change the index. - if is_copy: + if is_copy is not None: + warnings.warn( + "is_copy is deprecated and will be removed in a future version. " + "take will always return a copy in the future.", + FutureWarning, + stacklevel=2, + ) if not result._get_axis(axis).equals(self._get_axis(axis)): result._set_is_copy(self) + else: + is_copy = True return result @@ -4988,7 +4998,7 @@ def sample( ) locs = rs.choice(axis_length, size=n, replace=replace, p=weights) - return self.take(locs, axis=axis, is_copy=False) + return self.take(locs, axis=axis) _shared_docs[ "pipe" @@ -6983,7 +6993,7 @@ def asof(self, where, subset=None): # mask the missing missing = locs == -1 - data = self.take(locs, is_copy=False) + data = self.take(locs) data.index = where data.loc[missing] = np.nan return data if is_list else data.iloc[-1]