Skip to content

Commit 16d1dc0

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

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

pandas/core/generic.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -3355,7 +3355,9 @@ 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=True, **kwargs):
3359+
3360+
def take(self, indices, axis=0, is_copy=None, **kwargs):
33593361
"""
33603362
Return the elements in the given *positional* indices along an axis.
33613363
@@ -3372,6 +3374,8 @@ def take(self, indices, axis=0, is_copy=True, **kwargs):
33723374
selecting rows, ``1`` means that we are selecting columns.
33733375
is_copy : bool, default True
33743376
Whether to return a copy of the original object or not.
3377+
3378+
.. deprecated:: 0.25.2
33753379
**kwargs
33763380
For compatibility with :meth:`numpy.take`. Has no effect on the
33773381
output.
@@ -3430,6 +3434,14 @@ class max_speed
34303434
1 monkey mammal NaN
34313435
3 lion mammal 80.5
34323436
"""
3437+
if is_copy is not None:
3438+
warnings.warn(
3439+
"is_copy is deprecated and will be removed in a future version",
3440+
FutureWarning,
3441+
stacklevel=2,
3442+
)
3443+
is_copy = True
3444+
34333445
nv.validate_take(tuple(), kwargs)
34343446

34353447
self._consolidate_inplace()
@@ -5014,7 +5026,7 @@ def sample(
50145026
)
50155027

50165028
locs = rs.choice(axis_length, size=n, replace=replace, p=weights)
5017-
return self.take(locs, axis=axis, is_copy=False)
5029+
return self.take(locs, axis=axis)
50185030

50195031
_shared_docs[
50205032
"pipe"
@@ -7255,7 +7267,7 @@ def asof(self, where, subset=None):
72557267

72567268
# mask the missing
72577269
missing = locs == -1
7258-
data = self.take(locs, is_copy=False)
7270+
data = self.take(locs)
72597271
data.index = where
72607272
data.loc[missing] = np.nan
72617273
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)