Skip to content

Commit 44006b6

Browse files
lukemanleyphofl
authored andcommitted
DEPR: is_copy arg from take (pandas-dev#49221)
remove is_copy arg from take
1 parent c6351d7 commit 44006b6

File tree

5 files changed

+5
-50
lines changed

5 files changed

+5
-50
lines changed

doc/source/whatsnew/v2.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ Removal of prior version deprecations/changes
170170
- Disallow passing positional arguments to :meth:`MultiIndex.set_levels` and :meth:`MultiIndex.set_codes` (:issue:`41485`)
171171
- Removed argument ``how`` from :meth:`PeriodIndex.astype`, use :meth:`PeriodIndex.to_timestamp` instead (:issue:`37982`)
172172
- Removed argument ``try_cast`` from :meth:`DataFrame.mask`, :meth:`DataFrame.where`, :meth:`Series.mask` and :meth:`Series.where` (:issue:`38836`)
173+
- Removed argument ``is_copy`` from :meth:`DataFrame.take` and :meth:`Series.take` (:issue:`30615`)
173174
- Disallow passing non-round floats to :class:`Timestamp` with ``unit="M"`` or ``unit="Y"`` (:issue:`47266`)
174175
- Removed :meth:`.Rolling.validate`, :meth:`.Expanding.validate`, and :meth:`.ExponentialMovingWindow.validate` (:issue:`43665`)
175176
- Removed :attr:`Rolling.win_type` returning ``"freq"`` (:issue:`38963`)

pandas/core/generic.py

+1-17
Original file line numberDiff line numberDiff line change
@@ -3794,9 +3794,7 @@ def _clear_item_cache(self) -> None:
37943794
# ----------------------------------------------------------------------
37953795
# Indexing Methods
37963796

3797-
def take(
3798-
self: NDFrameT, indices, axis: Axis = 0, is_copy: bool_t | None = None, **kwargs
3799-
) -> NDFrameT:
3797+
def take(self: NDFrameT, indices, axis: Axis = 0, **kwargs) -> NDFrameT:
38003798
"""
38013799
Return the elements in the given *positional* indices along an axis.
38023800
@@ -3812,13 +3810,6 @@ def take(
38123810
The axis on which to select elements. ``0`` means that we are
38133811
selecting rows, ``1`` means that we are selecting columns.
38143812
For `Series` this parameter is unused and defaults to 0.
3815-
is_copy : bool
3816-
Before pandas 1.0, ``is_copy=False`` can be specified to ensure
3817-
that the return value is an actual copy. Starting with pandas 1.0,
3818-
``take`` always returns a copy, and the keyword is therefore
3819-
deprecated.
3820-
3821-
.. deprecated:: 1.0.0
38223813
**kwargs
38233814
For compatibility with :meth:`numpy.take`. Has no effect on the
38243815
output.
@@ -3877,13 +3868,6 @@ class max_speed
38773868
1 monkey mammal NaN
38783869
3 lion mammal 80.5
38793870
"""
3880-
if is_copy is not None:
3881-
warnings.warn(
3882-
"is_copy is deprecated and will be removed in a future version. "
3883-
"'take' always returns a copy, so there is no need to specify this.",
3884-
FutureWarning,
3885-
stacklevel=find_stack_level(),
3886-
)
38873871

38883872
nv.validate_take((), kwargs)
38893873

pandas/core/groupby/generic.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -856,12 +856,9 @@ def take(
856856
self,
857857
indices: TakeIndexer,
858858
axis: Axis = 0,
859-
is_copy: bool | None = None,
860859
**kwargs,
861860
) -> Series:
862-
result = self._op_via_apply(
863-
"take", indices=indices, axis=axis, is_copy=is_copy, **kwargs
864-
)
861+
result = self._op_via_apply("take", indices=indices, axis=axis, **kwargs)
865862
return result
866863

867864
@doc(Series.skew.__doc__)
@@ -2254,12 +2251,9 @@ def take(
22542251
self,
22552252
indices: TakeIndexer,
22562253
axis: Axis | None = 0,
2257-
is_copy: bool | None = None,
22582254
**kwargs,
22592255
) -> DataFrame:
2260-
result = self._op_via_apply(
2261-
"take", indices=indices, axis=axis, is_copy=is_copy, **kwargs
2262-
)
2256+
result = self._op_via_apply("take", indices=indices, axis=axis, **kwargs)
22632257
return result
22642258

22652259
@doc(DataFrame.skew.__doc__)

pandas/core/series.py

+1-10
Original file line numberDiff line numberDiff line change
@@ -889,16 +889,7 @@ def axes(self) -> list[Index]:
889889
# Indexing Methods
890890

891891
@Appender(NDFrame.take.__doc__)
892-
def take(
893-
self, indices, axis: Axis = 0, is_copy: bool | None = None, **kwargs
894-
) -> Series:
895-
if is_copy is not None:
896-
warnings.warn(
897-
"is_copy is deprecated and will be removed in a future version. "
898-
"'take' always returns a copy, so there is no need to specify this.",
899-
FutureWarning,
900-
stacklevel=find_stack_level(),
901-
)
892+
def take(self, indices, axis: Axis = 0, **kwargs) -> Series:
902893
nv.validate_take((), kwargs)
903894

904895
indices = ensure_platform_int(indices)

pandas/tests/generic/test_generic.py

-15
Original file line numberDiff line numberDiff line change
@@ -429,21 +429,6 @@ def test_take_invalid_kwargs(self, frame_or_series):
429429
with pytest.raises(ValueError, match=msg):
430430
obj.take(indices, mode="clip")
431431

432-
@pytest.mark.parametrize("is_copy", [True, False])
433-
def test_depr_take_kwarg_is_copy(self, is_copy, frame_or_series):
434-
# GH 27357
435-
obj = DataFrame({"A": [1, 2, 3]})
436-
obj = tm.get_obj(obj, frame_or_series)
437-
438-
msg = (
439-
"is_copy is deprecated and will be removed in a future version. "
440-
"'take' always returns a copy, so there is no need to specify this."
441-
)
442-
with tm.assert_produces_warning(FutureWarning) as w:
443-
obj.take([0, 1], is_copy=is_copy)
444-
445-
assert w[0].message.args[0] == msg
446-
447432
def test_axis_classmethods(self, frame_or_series):
448433
box = frame_or_series
449434
obj = box(dtype=object)

0 commit comments

Comments
 (0)