Skip to content

Commit

Permalink
deprecate is_copy argument of take and remove is_copy=False usage
Browse files Browse the repository at this point in the history
  • Loading branch information
ryankarlos committed Jan 2, 2020
1 parent 9871bdd commit 6f4c0fc
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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

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

0 comments on commit 6f4c0fc

Please sign in to comment.