From 101786a5e92c267c2185d1723ed6e8d0b501f0ef Mon Sep 17 00:00:00 2001 From: Ryan Nazareth Date: Fri, 3 Jan 2020 00:26:32 +0000 Subject: [PATCH] Fix condition for is_copy to avoid breaking other tests --- pandas/core/generic.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 3414e345c1a9ba..856902ada64fe5 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -3336,6 +3336,16 @@ class max_speed 1 monkey mammal NaN 3 lion mammal 80.5 """ + 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, + ) + else: + is_copy = True + nv.validate_take(tuple(), kwargs) self._consolidate_inplace() @@ -3346,17 +3356,9 @@ class max_speed result = self._constructor(new_data).__finalize__(self) # Maybe set copy if we didn't actually change the index. - 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 is_copy: if not result._get_axis(axis).equals(self._get_axis(axis)): result._set_is_copy(self) - else: - is_copy = True return result @@ -4998,7 +5000,7 @@ def sample( ) locs = rs.choice(axis_length, size=n, replace=replace, p=weights) - return self.take(locs, axis=axis) + return self.take(locs, is_copy=False, axis=axis) _shared_docs[ "pipe" @@ -6993,7 +6995,7 @@ def asof(self, where, subset=None): # mask the missing missing = locs == -1 - data = self.take(locs) + data = self.take(locs, is_copy=False) data.index = where data.loc[missing] = np.nan return data if is_list else data.iloc[-1]