Skip to content

Commit

Permalink
Fix condition for is_copy to avoid breaking other tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ryankarlos committed Jan 3, 2020
1 parent ac08070 commit 101786a
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 101786a

Please sign in to comment.