-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Deprecate non-keyword arguments in drop #41486
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
simonjayhawkins
merged 11 commits into
pandas-dev:master
from
MarcoGorelli:deprecate-nonkeyword-args-drop
May 27, 2021
Merged
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e3f08cc
deprecate non-keyword arguments in drop
MarcoGorelli 7912d31
noop
MarcoGorelli 685a566
add series test
MarcoGorelli 7f4ac1a
assert result in test
MarcoGorelli cefd12d
Merge remote-tracking branch 'upstream/master' into deprecate-nonkeyw…
MarcoGorelli 0e4bc2e
Merge branch 'master' into deprecate-nonkeyword-args-drop
jreback d2405ef
Merge branch 'master' into deprecate-nonkeyword-args-drop
jreback dc2323a
Merge branch 'master' into deprecate-nonkeyword-args-drop
jreback 46fdb4e
Merge branch 'master' into deprecate-nonkeyword-args-drop
jreback 419b664
Merge branch 'master' into deprecate-nonkeyword-args-drop
jreback bf87b1f
Merge branch 'master' into deprecate-nonkeyword-args-drop
MarcoGorelli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,7 +89,7 @@ def test_drop_names(self): | |
with pytest.raises(KeyError, match=msg): | ||
df.drop(["g"]) | ||
with pytest.raises(KeyError, match=msg): | ||
df.drop(["g"], 1) | ||
df.drop(["g"], axis=1) | ||
|
||
# errors = 'ignore' | ||
dropped = df.drop(["g"], errors="ignore") | ||
|
@@ -123,11 +123,11 @@ def test_drop(self): | |
with pytest.raises(KeyError, match=r"\[5\] not found in axis"): | ||
simple.drop(5) | ||
with pytest.raises(KeyError, match=r"\['C'\] not found in axis"): | ||
simple.drop("C", 1) | ||
simple.drop("C", axis=1) | ||
with pytest.raises(KeyError, match=r"\[5\] not found in axis"): | ||
simple.drop([1, 5]) | ||
with pytest.raises(KeyError, match=r"\['C'\] not found in axis"): | ||
simple.drop(["A", "C"], 1) | ||
simple.drop(["A", "C"], axis=1) | ||
|
||
# errors = 'ignore' | ||
tm.assert_frame_equal(simple.drop(5, errors="ignore"), simple) | ||
|
@@ -201,7 +201,7 @@ def test_drop_api_equivalence(self): | |
res2 = df.drop(index="a") | ||
tm.assert_frame_equal(res1, res2) | ||
|
||
res1 = df.drop("d", 1) | ||
res1 = df.drop("d", axis=1) | ||
res2 = df.drop(columns="d") | ||
tm.assert_frame_equal(res1, res2) | ||
|
||
|
@@ -481,3 +481,13 @@ def test_drop_with_duplicate_columns2(self): | |
df2 = df.take([2, 0, 1, 2, 1], axis=1) | ||
result = df2.drop("C", axis=1) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
def test_drop_pos_args_deprecation(self): | ||
# https://github.com/pandas-dev/pandas/issues/41485 | ||
df = DataFrame({"a": [1, 2, 3]}) | ||
msg = ( | ||
r"Starting with Pandas version 2\.0 all arguments of drop except for the " | ||
r"arguments 'self' and 'labels' will be keyword-only" | ||
) | ||
with tm.assert_produces_warning(FutureWarning, match=msg): | ||
df.drop("a", 1) | ||
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 an assert that the result is still the same as |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,3 +84,14 @@ def test_drop_non_empty_list(data, index, drop_labels): | |
ser = Series(data=data, index=index, dtype=dtype) | ||
with pytest.raises(KeyError, match="not found in axis"): | ||
ser.drop(drop_labels) | ||
|
||
|
||
def test_drop_pos_args_deprecation(): | ||
# https://github.com/pandas-dev/pandas/issues/41485 | ||
ser = Series([1, 2, 3]) | ||
msg = ( | ||
r"Starting with Pandas version 2\.0 all arguments of drop except for the " | ||
r"arguments 'self' and 'labels' will be keyword-only" | ||
) | ||
with tm.assert_produces_warning(FutureWarning, match=msg): | ||
ser.drop(1, 0) | ||
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. Same here |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
as per other comments, we could consider deprecating some compatibility parameters on Series at the same time.