-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
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
ENH: Add ignore_index for df.drop_duplicates #30405
Merged
jreback
merged 15 commits into
pandas-dev:master
from
charlesdong1991:fix_issue_30114_duplicates
Dec 27, 2019
Merged
Changes from 7 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7e461a1
remove \n from docstring
charlesdong1991 1314059
fix conflicts
charlesdong1991 8bcb313
Merge remote-tracking branch 'upstream/master'
charlesdong1991 3faf5cc
Merge remote-tracking branch 'upstream/master' into fix_issue_30114_d…
charlesdong1991 bdda8ca
Add ignore_index for drop duplicates
charlesdong1991 6e76e56
add forgotten test and code change based on review
charlesdong1991 c12beb6
code change on WA review
charlesdong1991 1b6dc51
keep consistency
charlesdong1991 17dbcb0
code change based on JR review
charlesdong1991 a173eea
add test
charlesdong1991 4a37e8f
restore wrong deleted code
charlesdong1991 79a49e1
remove
charlesdong1991 5fb6e54
Merge remote-tracking branch 'upstream/master' into fix_issue_30114_d…
charlesdong1991 a8552d8
code change based on JR review
charlesdong1991 6eaff2e
simplify code
charlesdong1991 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 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 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 |
---|---|---|
|
@@ -4587,6 +4587,7 @@ def drop_duplicates( | |
subset: Optional[Union[Hashable, Sequence[Hashable]]] = None, | ||
keep: Union[str, bool] = "first", | ||
inplace: bool = False, | ||
ignore_index: bool = False, | ||
) -> Optional["DataFrame"]: | ||
""" | ||
Return DataFrame with duplicate rows removed. | ||
|
@@ -4606,6 +4607,8 @@ def drop_duplicates( | |
- False : Drop all duplicates. | ||
inplace : bool, default False | ||
Whether to drop duplicates in place or to return a copy. | ||
ignore_index : bool, default False | ||
If True, the resulting axis will be labeled 0, 1, …, n - 1. | ||
jreback marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Returns | ||
------- | ||
|
@@ -4621,9 +4624,15 @@ def drop_duplicates( | |
if inplace: | ||
(inds,) = (-duplicated)._ndarray_values.nonzero() | ||
new_data = self._data.take(inds) | ||
|
||
if ignore_index: | ||
jreback marked this conversation as resolved.
Show resolved
Hide resolved
|
||
new_data.axes[1] = ibase.default_index(len(inds)) | ||
jreback marked this conversation as resolved.
Show resolved
Hide resolved
jreback marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self._update_inplace(new_data) | ||
else: | ||
return self[-duplicated] | ||
result = self[-duplicated] | ||
if ignore_index: | ||
return result.reset_index(drop=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. here you have to copy before you update the index 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. i did not use copy, but |
||
return result | ||
|
||
return None | ||
|
||
|
This file contains 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.
reverse the ordering here, e.g. .drop_duplicates has gained the
ignore_index
keyword.move to other enhancements
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.
moved and rephrased!