-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Fix no raise dup index when using drop with axis=0 #19230
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
+56
−17
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d0b39ea
DOC: Updated doc
f43dbf8
TST: Added test for dropping index with dup cols
a4618bf
BUG: Raise on drop on dup index
b49f78d
DOC: Fixed docs
43fe5b0
Use numpy all
7ceafa1
TST: Updated tests to account for KeyError now being raised
5f7e6a2
DOC: Moved string to diff location
6c7bcf2
BUG: Updated code to raise KeyError
fa4c9fe
DOC: Updated doc to include correct err being raised.
adf2283
DOC: Updated docstring and documentation
c02c400
Merge branch 'master' into fix-no-raise-dup-cols
aschade 85e0094
Merge branch 'master' into fix-no-raise-dup-cols
aschade 556f959
Update v0.23.0.txt
aschade 5776bf3
DOC/TST: Updated docstring to show method correctly and updated test
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 |
---|---|---|
|
@@ -41,8 +41,8 @@ def test_drop_names(self): | |
assert obj.columns.name == 'second' | ||
assert list(df.columns) == ['d', 'e', 'f'] | ||
|
||
pytest.raises(ValueError, df.drop, ['g']) | ||
pytest.raises(ValueError, df.drop, ['g'], 1) | ||
pytest.raises(KeyError, df.drop, ['g']) | ||
pytest.raises(KeyError, df.drop, ['g'], 1) | ||
|
||
# errors = 'ignore' | ||
dropped = df.drop(['g'], errors='ignore') | ||
|
@@ -87,10 +87,10 @@ def test_drop(self): | |
assert_frame_equal(simple.drop( | ||
[0, 3], axis='index'), simple.loc[[1, 2], :]) | ||
|
||
pytest.raises(ValueError, simple.drop, 5) | ||
pytest.raises(ValueError, simple.drop, 'C', 1) | ||
pytest.raises(ValueError, simple.drop, [1, 5]) | ||
pytest.raises(ValueError, simple.drop, ['A', 'C'], 1) | ||
pytest.raises(KeyError, simple.drop, 5) | ||
pytest.raises(KeyError, simple.drop, 'C', 1) | ||
pytest.raises(KeyError, simple.drop, [1, 5]) | ||
pytest.raises(KeyError, simple.drop, ['A', 'C'], 1) | ||
|
||
# errors = 'ignore' | ||
assert_frame_equal(simple.drop(5, errors='ignore'), simple) | ||
|
@@ -1128,3 +1128,26 @@ def test_reindex_multi(self): | |
expected = df.reindex([0, 1]).reindex(columns=['a', 'b']) | ||
|
||
assert_frame_equal(result, expected) | ||
|
||
data = [[1, 2, 3], [1, 2, 3]] | ||
|
||
@pytest.mark.parametrize('actual', [ | ||
DataFrame(data=data, index=['a', 'a']), | ||
DataFrame(data=data, index=['a', 'b']), | ||
DataFrame(data=data, index=['a', 'b']).set_index([0, 1]), | ||
DataFrame(data=data, index=['a', 'a']).set_index([0, 1]) | ||
]) | ||
def test_raise_on_drop_duplicate_index(self, actual): | ||
|
||
# issue 19186 | ||
level = 0 if isinstance(actual.index, MultiIndex) else None | ||
with pytest.raises(KeyError): | ||
actual.drop('c', level=level, axis=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. Split this into multiple |
||
with pytest.raises(KeyError): | ||
actual.T.drop('c', level=level, axis=1) | ||
expected_no_err = actual.drop('c', axis=0, level=level, | ||
errors='ignore') | ||
assert_frame_equal(expected_no_err, actual) | ||
expected_no_err = actual.T.drop('c', axis=1, level=level, | ||
errors='ignore') | ||
assert_frame_equal(expected_no_err.T, actual) |
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
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.
need to update the doc-strings for all (Index,Series,DataFrame,Panel) for drop to change ValueError -> KeyError in the Raises section (or add it if its not there)