Skip to content

Commit 49a2fff

Browse files
committed
DEPR: is_copy arg of take closes pandas-dev#27357
1 parent c4489cb commit 49a2fff

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

pandas/core/generic.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -3355,7 +3355,7 @@ def _clear_item_cache(self):
33553355
# ----------------------------------------------------------------------
33563356
# Indexing Methods
33573357

3358-
def take(self, indices, axis=0, is_copy=True, **kwargs):
3358+
def take(self, indices, axis=0, is_copy=None, **kwargs):
33593359
"""
33603360
Return the elements in the given *positional* indices along an axis.
33613361
@@ -3372,6 +3372,8 @@ def take(self, indices, axis=0, is_copy=True, **kwargs):
33723372
selecting rows, ``1`` means that we are selecting columns.
33733373
is_copy : bool, default True
33743374
Whether to return a copy of the original object or not.
3375+
3376+
.. deprecated:: 0.25.2
33753377
**kwargs
33763378
For compatibility with :meth:`numpy.take`. Has no effect on the
33773379
output.
@@ -3430,6 +3432,14 @@ class max_speed
34303432
1 monkey mammal NaN
34313433
3 lion mammal 80.5
34323434
"""
3435+
if is_copy is not None:
3436+
warnings.warn(
3437+
"is_copy is deprecated and will be removed in a future version",
3438+
FutureWarning,
3439+
stacklevel=2,
3440+
)
3441+
is_copy = True
3442+
34333443
nv.validate_take(tuple(), kwargs)
34343444

34353445
self._consolidate_inplace()
@@ -5014,7 +5024,7 @@ def sample(
50145024
)
50155025

50165026
locs = rs.choice(axis_length, size=n, replace=replace, p=weights)
5017-
return self.take(locs, axis=axis, is_copy=False)
5027+
return self.take(locs, axis=axis)
50185028

50195029
_shared_docs[
50205030
"pipe"
@@ -7255,7 +7265,7 @@ def asof(self, where, subset=None):
72557265

72567266
# mask the missing
72577267
missing = locs == -1
7258-
data = self.take(locs, is_copy=False)
7268+
data = self.take(locs)
72597269
data.index = where
72607270
data.loc[missing] = np.nan
72617271
return data if is_list else data.iloc[-1]

pandas/tests/generic/test_generic.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ def test_pct_change(self, periods, fill_method, limit, exp):
589589
class TestNDFrame:
590590
# tests that don't fit elsewhere
591591

592-
def test_sample(sel):
592+
def test_sample(self):
593593
# Fixes issue: 2419
594594
# additional specific object based tests
595595

@@ -800,6 +800,11 @@ def test_take_invalid_kwargs(self):
800800
with pytest.raises(ValueError, match=msg):
801801
obj.take(indices, mode="clip")
802802

803+
def test_take_deprecated_kwarg_is_copy(self):
804+
df = DataFrame([1, 2])
805+
with tm.assert_produces_warning(FutureWarning):
806+
df.take([0, 1], is_copy=True)
807+
803808
def test_equals(self):
804809
s1 = pd.Series([1, 2, 3], index=[0, 2, 1])
805810
s2 = s1.copy()

0 commit comments

Comments
 (0)