Skip to content

Commit 7ef4874

Browse files
committed
deprecate is_copy argument of take and remove is_copy=False usage
1 parent 1e32421 commit 7ef4874

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

pandas/core/generic.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -3263,7 +3263,7 @@ def _clear_item_cache(self) -> None:
32633263
# Indexing Methods
32643264

32653265
def take(
3266-
self: FrameOrSeries, indices, axis=0, is_copy: bool_t = True, **kwargs
3266+
self: FrameOrSeries, indices, axis=0, is_copy: bool_t = None, **kwargs
32673267
) -> FrameOrSeries:
32683268
"""
32693269
Return the elements in the given *positional* indices along an axis.
@@ -3281,6 +3281,8 @@ def take(
32813281
selecting rows, ``1`` means that we are selecting columns.
32823282
is_copy : bool, default True
32833283
Whether to return a copy of the original object or not.
3284+
3285+
.. deprecated:: 1.0.0
32843286
**kwargs
32853287
For compatibility with :meth:`numpy.take`. Has no effect on the
32863288
output.
@@ -3349,9 +3351,17 @@ class max_speed
33493351
result = self._constructor(new_data).__finalize__(self)
33503352

33513353
# Maybe set copy if we didn't actually change the index.
3352-
if is_copy:
3354+
if is_copy is not None:
3355+
warnings.warn(
3356+
"is_copy is deprecated and will be removed in a future version. "
3357+
"take will always return a copy in the future.",
3358+
FutureWarning,
3359+
stacklevel=2,
3360+
)
33533361
if not result._get_axis(axis).equals(self._get_axis(axis)):
33543362
result._set_is_copy(self)
3363+
else:
3364+
is_copy = True
33553365

33563366
return result
33573367

@@ -4997,7 +5007,7 @@ def sample(
49975007
)
49985008

49995009
locs = rs.choice(axis_length, size=n, replace=replace, p=weights)
5000-
return self.take(locs, axis=axis, is_copy=False)
5010+
return self.take(locs, axis=axis)
50015011

50025012
_shared_docs[
50035013
"pipe"
@@ -6994,7 +7004,7 @@ def asof(self, where, subset=None):
69947004

69957005
# mask the missing
69967006
missing = locs == -1
6997-
data = self.take(locs, is_copy=False)
7007+
data = self.take(locs)
69987008
data.index = where
69997009
data.loc[missing] = np.nan
70007010
return data if is_list else data.iloc[-1]

0 commit comments

Comments
 (0)