-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DEPR: is_copy arg of take closes #27357 #28751
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3355,7 +3355,7 @@ def _clear_item_cache(self): | |
# ---------------------------------------------------------------------- | ||
# Indexing Methods | ||
|
||
def take(self, indices, axis=0, is_copy=True, **kwargs): | ||
def take(self, indices, axis=0, is_copy=None, **kwargs): | ||
""" | ||
Return the elements in the given *positional* indices along an axis. | ||
|
||
|
@@ -3372,6 +3372,8 @@ def take(self, indices, axis=0, is_copy=True, **kwargs): | |
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:: 0.25.2 | ||
**kwargs | ||
For compatibility with :meth:`numpy.take`. Has no effect on the | ||
output. | ||
|
@@ -3430,6 +3432,14 @@ 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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add that 'take' will always return a copy in the future? |
||
FutureWarning, | ||
stacklevel=2, | ||
) | ||
is_copy = True | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this assignment even required? Not used later in the function body right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But, we should only put it to True if it was None (to keep the existing behaviour), so put it in an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is used: # Maybe set copy if we didn't actually change the index.
if is_copy:
if not result._get_axis(axis).equals(self._get_axis(axis)):
result._set_is_copy(self)
return result But is_copy is already deprecated. I think it needs to be removed for 1.0. Since this is going into 1.0 I am thinking now that instead of deprecating this parameter it needs to be removed all together, along with |
||
|
||
nv.validate_take(tuple(), kwargs) | ||
|
||
self._consolidate_inplace() | ||
|
@@ -5014,7 +5024,7 @@ def sample( | |
) | ||
|
||
locs = rs.choice(axis_length, size=n, replace=replace, p=weights) | ||
return self.take(locs, axis=axis, is_copy=False) | ||
return self.take(locs, axis=axis) | ||
|
||
_shared_docs[ | ||
"pipe" | ||
|
@@ -7255,7 +7265,7 @@ def asof(self, where, subset=None): | |
|
||
# mask the missing | ||
missing = locs == -1 | ||
data = self.take(locs, is_copy=False) | ||
data = self.take(locs) | ||
data.index = where | ||
data.loc[missing] = np.nan | ||
return data if is_list else data.iloc[-1] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -589,7 +589,7 @@ def test_pct_change(self, periods, fill_method, limit, exp): | |
class TestNDFrame: | ||
# tests that don't fit elsewhere | ||
|
||
def test_sample(sel): | ||
def test_sample(self): | ||
# Fixes issue: 2419 | ||
# additional specific object based tests | ||
|
||
|
@@ -800,6 +800,11 @@ def test_take_invalid_kwargs(self): | |
with pytest.raises(ValueError, match=msg): | ||
obj.take(indices, mode="clip") | ||
|
||
def test_take_deprecated_kwarg_is_copy(self): | ||
df = DataFrame([1, 2]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reference issue number above |
||
with tm.assert_produces_warning(FutureWarning): | ||
df.take([0, 1], is_copy=True) | ||
|
||
def test_equals(self): | ||
s1 = pd.Series([1, 2, 3], index=[0, 2, 1]) | ||
s2 = s1.copy() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be 1.0.0 at this point