Skip to content

Commit c854a8a

Browse files
Revert "DEPR: is_copy arg of take (pandas-dev#30615)"
This reverts commit 7796be6.
1 parent 8718877 commit c854a8a

File tree

5 files changed

+4
-33
lines changed

5 files changed

+4
-33
lines changed

doc/source/whatsnew/v1.0.0.rst

-1
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,6 @@ Deprecations
703703
- The deprecated internal attributes ``_start``, ``_stop`` and ``_step`` of :class:`RangeIndex` now raise a ``FutureWarning`` instead of a ``DeprecationWarning`` (:issue:`26581`)
704704
- The ``pandas.util.testing`` module has been deprecated. Use the public API in ``pandas.testing`` documented at :ref:`api.general.testing` (:issue:`16232`).
705705
- ``pandas.SparseArray`` has been deprecated. Use ``pandas.arrays.SparseArray`` (:class:`arrays.SparseArray`) instead. (:issue:`30642`)
706-
- The parameter ``is_copy`` of :meth:`DataFrame.take` has been deprecated and will be removed in a future version. (:issue:`27357`)
707706
- Support for multi-dimensional indexing (e.g. ``index[:, None]``) on a :class:`Index` is deprecated and will be removed in a future version, convert to a numpy array before indexing instead (:issue:`30588`)
708707
- The ``pandas.np`` submodule is now deprecated. Import numpy directly instead (:issue:`30296`)
709708
- The ``pandas.datetime`` class is now deprecated. Import from ``datetime`` instead (:issue:`30610`)

pandas/core/generic.py

+3-16
Original file line numberDiff line numberDiff line change
@@ -3262,7 +3262,7 @@ def _clear_item_cache(self) -> None:
32623262
# Indexing Methods
32633263

32643264
def take(
3265-
self: FrameOrSeries, indices, axis=0, is_copy: Optional[bool_t] = None, **kwargs
3265+
self: FrameOrSeries, indices, axis=0, is_copy: bool_t = True, **kwargs
32663266
) -> FrameOrSeries:
32673267
"""
32683268
Return the elements in the given *positional* indices along an axis.
@@ -3280,8 +3280,6 @@ def take(
32803280
selecting rows, ``1`` means that we are selecting columns.
32813281
is_copy : bool, default True
32823282
Whether to return a copy of the original object or not.
3283-
3284-
.. deprecated:: 1.0.0
32853283
**kwargs
32863284
For compatibility with :meth:`numpy.take`. Has no effect on the
32873285
output.
@@ -3340,16 +3338,6 @@ class max_speed
33403338
1 monkey mammal NaN
33413339
3 lion mammal 80.5
33423340
"""
3343-
if is_copy is not None:
3344-
warnings.warn(
3345-
"is_copy is deprecated and will be removed in a future version. "
3346-
"take will always return a copy in the future.",
3347-
FutureWarning,
3348-
stacklevel=2,
3349-
)
3350-
else:
3351-
is_copy = True
3352-
33533341
nv.validate_take(tuple(), kwargs)
33543342

33553343
self._consolidate_inplace()
@@ -4949,7 +4937,7 @@ def sample(
49494937
)
49504938

49514939
locs = rs.choice(axis_length, size=n, replace=replace, p=weights)
4952-
return self.take(locs, axis=axis)
4940+
return self.take(locs, axis=axis, is_copy=False)
49534941

49544942
_shared_docs[
49554943
"pipe"
@@ -6934,8 +6922,7 @@ def asof(self, where, subset=None):
69346922

69356923
# mask the missing
69366924
missing = locs == -1
6937-
d = self.take(locs)
6938-
data = d.copy()
6925+
data = self.take(locs, is_copy=False)
69396926
data.index = where
69406927
data.loc[missing] = np.nan
69416928
return data if is_list else data.iloc[-1]

pandas/core/groupby/grouper.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def _set_grouper(self, obj: FrameOrSeries, sort: bool = False):
194194
# use stable sort to support first, last, nth
195195
indexer = self.indexer = ax.argsort(kind="mergesort")
196196
ax = ax.take(indexer)
197-
obj = obj.take(indexer, axis=self.axis)
197+
obj = obj.take(indexer, axis=self.axis, is_copy=False)
198198

199199
self.obj = obj
200200
self.grouper = ax

pandas/tests/frame/methods/test_asof.py

-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ def test_basic(self, date_range_frame):
3030
ub = df.index[30]
3131

3232
dates = list(dates)
33-
3433
result = df.asof(dates)
3534
assert result.notna().all(1).all()
3635

@@ -66,7 +65,6 @@ def test_missing(self, date_range_frame):
6665
# no match found - `where` value before earliest date in index
6766
N = 10
6867
df = date_range_frame.iloc[:N].copy()
69-
7068
result = df.asof("1989-12-31")
7169

7270
expected = Series(
@@ -140,6 +138,5 @@ def test_time_zone_aware_index(self, stamp, expected):
140138
Timestamp("2018-01-01 22:35:10.550+00:00"),
141139
],
142140
)
143-
144141
result = df.asof(stamp)
145142
tm.assert_series_equal(result, expected)

pandas/tests/generic/test_generic.py

-12
Original file line numberDiff line numberDiff line change
@@ -817,18 +817,6 @@ def test_take_invalid_kwargs(self):
817817
with pytest.raises(ValueError, match=msg):
818818
obj.take(indices, mode="clip")
819819

820-
def test_depr_take_kwarg_is_copy(self):
821-
# GH 27357
822-
df = DataFrame({"A": [1, 2, 3]})
823-
msg = (
824-
"is_copy is deprecated and will be removed in a future version. "
825-
"take will always return a copy in the future."
826-
)
827-
with tm.assert_produces_warning(FutureWarning) as w:
828-
df.take([0, 1], is_copy=True)
829-
830-
assert w[0].message.args[0] == msg
831-
832820
def test_equals(self):
833821
s1 = pd.Series([1, 2, 3], index=[0, 2, 1])
834822
s2 = s1.copy()

0 commit comments

Comments
 (0)