Skip to content

DEPR: is_copy arg from take #49221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ Removal of prior version deprecations/changes
- Remove argument ``inplace`` from :meth:`MultiIndex.set_levels` and :meth:`MultiIndex.set_codes` (:issue:`35626`)
- Disallow passing positional arguments to :meth:`MultiIndex.set_levels` and :meth:`MultiIndex.set_codes` (:issue:`41485`)
- Removed argument ``try_cast`` from :meth:`DataFrame.mask`, :meth:`DataFrame.where`, :meth:`Series.mask` and :meth:`Series.where` (:issue:`38836`)
- Removed argument ``is_copy`` from :meth:`DataFrame.take` and :meth:`Series.take` (:issue:`30615`)
- Disallow passing non-round floats to :class:`Timestamp` with ``unit="M"`` or ``unit="Y"`` (:issue:`47266`)
- Removed deprecated :meth:`Timedelta.delta`, :meth:`Timedelta.is_populated`, and :attr:`Timedelta.freq` (:issue:`46430`, :issue:`46476`)
- Removed the ``numeric_only`` keyword from :meth:`Categorical.min` and :meth:`Categorical.max` in favor of ``skipna`` (:issue:`48821`)
Expand Down
18 changes: 1 addition & 17 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3794,9 +3794,7 @@ def _clear_item_cache(self) -> None:
# ----------------------------------------------------------------------
# Indexing Methods

def take(
self: NDFrameT, indices, axis: Axis = 0, is_copy: bool_t | None = None, **kwargs
) -> NDFrameT:
def take(self: NDFrameT, indices, axis: Axis = 0, **kwargs) -> NDFrameT:
"""
Return the elements in the given *positional* indices along an axis.

Expand All @@ -3812,13 +3810,6 @@ def take(
The axis on which to select elements. ``0`` means that we are
selecting rows, ``1`` means that we are selecting columns.
For `Series` this parameter is unused and defaults to 0.
is_copy : bool
Before pandas 1.0, ``is_copy=False`` can be specified to ensure
that the return value is an actual copy. Starting with pandas 1.0,
``take`` always returns a copy, and the keyword is therefore
deprecated.

.. deprecated:: 1.0.0
**kwargs
For compatibility with :meth:`numpy.take`. Has no effect on the
output.
Expand Down Expand Up @@ -3877,13 +3868,6 @@ class max_speed
1 monkey mammal NaN
3 lion mammal 80.5
"""
if is_copy is not None:
warnings.warn(
"is_copy is deprecated and will be removed in a future version. "
"'take' always returns a copy, so there is no need to specify this.",
FutureWarning,
stacklevel=find_stack_level(),
)

nv.validate_take((), kwargs)

Expand Down
10 changes: 2 additions & 8 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,12 +856,9 @@ def take(
self,
indices: TakeIndexer,
axis: Axis = 0,
is_copy: bool | None = None,
**kwargs,
) -> Series:
result = self._op_via_apply(
"take", indices=indices, axis=axis, is_copy=is_copy, **kwargs
)
result = self._op_via_apply("take", indices=indices, axis=axis, **kwargs)
return result

@doc(Series.skew.__doc__)
Expand Down Expand Up @@ -2254,12 +2251,9 @@ def take(
self,
indices: TakeIndexer,
axis: Axis | None = 0,
is_copy: bool | None = None,
**kwargs,
) -> DataFrame:
result = self._op_via_apply(
"take", indices=indices, axis=axis, is_copy=is_copy, **kwargs
)
result = self._op_via_apply("take", indices=indices, axis=axis, **kwargs)
return result

@doc(DataFrame.skew.__doc__)
Expand Down
11 changes: 1 addition & 10 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,16 +889,7 @@ def axes(self) -> list[Index]:
# Indexing Methods

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

indices = ensure_platform_int(indices)
Expand Down
15 changes: 0 additions & 15 deletions pandas/tests/generic/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,21 +429,6 @@ def test_take_invalid_kwargs(self, frame_or_series):
with pytest.raises(ValueError, match=msg):
obj.take(indices, mode="clip")

@pytest.mark.parametrize("is_copy", [True, False])
def test_depr_take_kwarg_is_copy(self, is_copy, frame_or_series):
# GH 27357
obj = DataFrame({"A": [1, 2, 3]})
obj = tm.get_obj(obj, frame_or_series)

msg = (
"is_copy is deprecated and will be removed in a future version. "
"'take' always returns a copy, so there is no need to specify this."
)
with tm.assert_produces_warning(FutureWarning) as w:
obj.take([0, 1], is_copy=is_copy)

assert w[0].message.args[0] == msg

def test_axis_classmethods(self, frame_or_series):
box = frame_or_series
obj = box(dtype=object)
Expand Down