Skip to content

Commit 3475d83

Browse files
authored
Remove support for slices in take (#57343)
1 parent 590d6ed commit 3475d83

File tree

3 files changed

+8
-21
lines changed

3 files changed

+8
-21
lines changed

doc/source/whatsnew/v3.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ Removal of prior version deprecations/changes
133133
- Removed deprecated behavior of :meth:`Series.agg` using :meth:`Series.apply` (:issue:`53325`)
134134
- Removed support for :class:`DataFrame` in :meth:`DataFrame.from_records`(:issue:`51697`)
135135
- Removed support for ``errors="ignore"`` in :func:`to_datetime`, :func:`to_timedelta` and :func:`to_numeric` (:issue:`55734`)
136+
- Removed support for ``slice`` in :meth:`DataFrame.take` (:issue:`51539`)
136137
- Removed the ``ArrayManager`` (:issue:`55043`)
137138
- Removed the ``fastpath`` argument from the :class:`Series` constructor (:issue:`55466`)
138139
- Removed the ``is_boolean``, ``is_integer``, ``is_floating``, ``holds_integer``, ``is_numeric``, ``is_categorical``, ``is_object``, and ``is_interval`` attributes of :class:`Index` (:issue:`50042`)

pandas/core/generic.py

+4-18
Original file line numberDiff line numberDiff line change
@@ -3851,28 +3851,14 @@ class max_speed
38513851

38523852
nv.validate_take((), kwargs)
38533853

3854-
if not isinstance(indices, slice):
3855-
indices = np.asarray(indices, dtype=np.intp)
3856-
if axis == 0 and indices.ndim == 1 and is_range_indexer(indices, len(self)):
3857-
return self.copy(deep=False)
3858-
elif self.ndim == 1:
3854+
if isinstance(indices, slice):
38593855
raise TypeError(
38603856
f"{type(self).__name__}.take requires a sequence of integers, "
38613857
"not slice."
38623858
)
3863-
else:
3864-
warnings.warn(
3865-
# GH#51539
3866-
f"Passing a slice to {type(self).__name__}.take is deprecated "
3867-
"and will raise in a future version. Use `obj[slicer]` or pass "
3868-
"a sequence of integers instead.",
3869-
FutureWarning,
3870-
stacklevel=find_stack_level(),
3871-
)
3872-
# We can get here with a slice via DataFrame.__getitem__
3873-
indices = np.arange(
3874-
indices.start, indices.stop, indices.step, dtype=np.intp
3875-
)
3859+
indices = np.asarray(indices, dtype=np.intp)
3860+
if axis == 0 and indices.ndim == 1 and is_range_indexer(indices, len(self)):
3861+
return self.copy(deep=False)
38763862

38773863
new_data = self._mgr.take(
38783864
indices,

pandas/tests/frame/indexing/test_take.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55

66
class TestDataFrameTake:
7-
def test_take_slices_deprecated(self, float_frame):
7+
def test_take_slices_not_supported(self, float_frame):
88
# GH#51539
99
df = float_frame
1010

1111
slc = slice(0, 4, 1)
12-
with tm.assert_produces_warning(FutureWarning):
12+
with pytest.raises(TypeError, match="slice"):
1313
df.take(slc, axis=0)
14-
with tm.assert_produces_warning(FutureWarning):
14+
with pytest.raises(TypeError, match="slice"):
1515
df.take(slc, axis=1)
1616

1717
def test_take(self, float_frame):

0 commit comments

Comments
 (0)