Skip to content

Commit

Permalink
Revert "DEPR: is_copy arg of take (pandas-dev#30615)"
Browse files Browse the repository at this point in the history
This reverts commit 7796be6.
  • Loading branch information
jorisvandenbossche committed Jan 15, 2020
1 parent 8718877 commit c854a8a
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 33 deletions.
1 change: 0 additions & 1 deletion doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,6 @@ Deprecations
- The deprecated internal attributes ``_start``, ``_stop`` and ``_step`` of :class:`RangeIndex` now raise a ``FutureWarning`` instead of a ``DeprecationWarning`` (:issue:`26581`)
- The ``pandas.util.testing`` module has been deprecated. Use the public API in ``pandas.testing`` documented at :ref:`api.general.testing` (:issue:`16232`).
- ``pandas.SparseArray`` has been deprecated. Use ``pandas.arrays.SparseArray`` (:class:`arrays.SparseArray`) instead. (:issue:`30642`)
- The parameter ``is_copy`` of :meth:`DataFrame.take` has been deprecated and will be removed in a future version. (:issue:`27357`)
- 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`)
- The ``pandas.np`` submodule is now deprecated. Import numpy directly instead (:issue:`30296`)
- The ``pandas.datetime`` class is now deprecated. Import from ``datetime`` instead (:issue:`30610`)
Expand Down
19 changes: 3 additions & 16 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3262,7 +3262,7 @@ def _clear_item_cache(self) -> None:
# Indexing Methods

def take(
self: FrameOrSeries, indices, axis=0, is_copy: Optional[bool_t] = None, **kwargs
self: FrameOrSeries, indices, axis=0, is_copy: bool_t = True, **kwargs
) -> FrameOrSeries:
"""
Return the elements in the given *positional* indices along an axis.
Expand All @@ -3280,8 +3280,6 @@ def take(
selecting rows, ``1`` means that we are selecting columns.
is_copy : bool, default True
Whether to return a copy of the original object or not.
.. deprecated:: 1.0.0
**kwargs
For compatibility with :meth:`numpy.take`. Has no effect on the
output.
Expand Down Expand Up @@ -3340,16 +3338,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 will always return a copy in the future.",
FutureWarning,
stacklevel=2,
)
else:
is_copy = True

nv.validate_take(tuple(), kwargs)

self._consolidate_inplace()
Expand Down Expand Up @@ -4949,7 +4937,7 @@ def sample(
)

locs = rs.choice(axis_length, size=n, replace=replace, p=weights)
return self.take(locs, axis=axis)
return self.take(locs, axis=axis, is_copy=False)

_shared_docs[
"pipe"
Expand Down Expand Up @@ -6934,8 +6922,7 @@ def asof(self, where, subset=None):

# mask the missing
missing = locs == -1
d = self.take(locs)
data = d.copy()
data = self.take(locs, is_copy=False)
data.index = where
data.loc[missing] = np.nan
return data if is_list else data.iloc[-1]
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/groupby/grouper.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def _set_grouper(self, obj: FrameOrSeries, sort: bool = False):
# use stable sort to support first, last, nth
indexer = self.indexer = ax.argsort(kind="mergesort")
ax = ax.take(indexer)
obj = obj.take(indexer, axis=self.axis)
obj = obj.take(indexer, axis=self.axis, is_copy=False)

self.obj = obj
self.grouper = ax
Expand Down
3 changes: 0 additions & 3 deletions pandas/tests/frame/methods/test_asof.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def test_basic(self, date_range_frame):
ub = df.index[30]

dates = list(dates)

result = df.asof(dates)
assert result.notna().all(1).all()

Expand Down Expand Up @@ -66,7 +65,6 @@ def test_missing(self, date_range_frame):
# no match found - `where` value before earliest date in index
N = 10
df = date_range_frame.iloc[:N].copy()

result = df.asof("1989-12-31")

expected = Series(
Expand Down Expand Up @@ -140,6 +138,5 @@ def test_time_zone_aware_index(self, stamp, expected):
Timestamp("2018-01-01 22:35:10.550+00:00"),
],
)

result = df.asof(stamp)
tm.assert_series_equal(result, expected)
12 changes: 0 additions & 12 deletions pandas/tests/generic/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,18 +817,6 @@ def test_take_invalid_kwargs(self):
with pytest.raises(ValueError, match=msg):
obj.take(indices, mode="clip")

def test_depr_take_kwarg_is_copy(self):
# GH 27357
df = DataFrame({"A": [1, 2, 3]})
msg = (
"is_copy is deprecated and will be removed in a future version. "
"take will always return a copy in the future."
)
with tm.assert_produces_warning(FutureWarning) as w:
df.take([0, 1], is_copy=True)

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

def test_equals(self):
s1 = pd.Series([1, 2, 3], index=[0, 2, 1])
s2 = s1.copy()
Expand Down

0 comments on commit c854a8a

Please sign in to comment.