Skip to content

Commit c5219fc

Browse files
committed
deprecate is_copy argument of take and remove is_copy=False usage
1 parent 0913ed0 commit c5219fc

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
@@ -3259,7 +3259,7 @@ def _clear_item_cache(self) -> None:
32593259
# ----------------------------------------------------------------------
32603260
# Indexing Methods
32613261

3262-
def take(self, indices, axis=0, is_copy: bool_t = True, **kwargs):
3262+
def take(self, indices, axis=0, is_copy: bool_t = None, **kwargs):
32633263
"""
32643264
Return the elements in the given *positional* indices along an axis.
32653265
@@ -3276,6 +3276,8 @@ def take(self, indices, axis=0, is_copy: bool_t = True, **kwargs):
32763276
selecting rows, ``1`` means that we are selecting columns.
32773277
is_copy : bool, default True
32783278
Whether to return a copy of the original object or not.
3279+
3280+
.. deprecated:: 1.0.0
32793281
**kwargs
32803282
For compatibility with :meth:`numpy.take`. Has no effect on the
32813283
output.
@@ -3344,9 +3346,17 @@ class max_speed
33443346
result = self._constructor(new_data).__finalize__(self)
33453347

33463348
# Maybe set copy if we didn't actually change the index.
3347-
if is_copy:
3349+
if is_copy is not None:
3350+
warnings.warn(
3351+
"is_copy is deprecated and will be removed in a future version. "
3352+
"take will always return a copy in the future.",
3353+
FutureWarning,
3354+
stacklevel=2,
3355+
)
33483356
if not result._get_axis(axis).equals(self._get_axis(axis)):
33493357
result._set_is_copy(self)
3358+
else:
3359+
is_copy = True
33503360

33513361
return result
33523362

@@ -4988,7 +4998,7 @@ def sample(
49884998
)
49894999

49905000
locs = rs.choice(axis_length, size=n, replace=replace, p=weights)
4991-
return self.take(locs, axis=axis, is_copy=False)
5001+
return self.take(locs, axis=axis)
49925002

49935003
_shared_docs[
49945004
"pipe"
@@ -6983,7 +6993,7 @@ def asof(self, where, subset=None):
69836993

69846994
# mask the missing
69856995
missing = locs == -1
6986-
data = self.take(locs, is_copy=False)
6996+
data = self.take(locs)
69876997
data.index = where
69886998
data.loc[missing] = np.nan
69896999
return data if is_list else data.iloc[-1]

0 commit comments

Comments
 (0)