Skip to content

Commit df1201d

Browse files
committed
deprecate is_copy argument of take and remove is_copy=False usage
1 parent 50ae37d commit df1201d

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

pandas/core/generic.py

Lines changed: 14 additions & 4 deletions
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

@@ -5002,7 +5012,7 @@ def sample(
50025012
)
50035013

50045014
locs = rs.choice(axis_length, size=n, replace=replace, p=weights)
5005-
return self.take(locs, axis=axis, is_copy=False)
5015+
return self.take(locs, axis=axis)
50065016

50075017
_shared_docs[
50085018
"pipe"
@@ -6999,7 +7009,7 @@ def asof(self, where, subset=None):
69997009

70007010
# mask the missing
70017011
missing = locs == -1
7002-
data = self.take(locs, is_copy=False)
7012+
data = self.take(locs)
70037013
data.index = where
70047014
data.loc[missing] = np.nan
70057015
return data if is_list else data.iloc[-1]

0 commit comments

Comments
 (0)