-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
Changes from 5 commits
7e461a1
1314059
8bcb313
3faf5cc
bdda8ca
6e76e56
c12beb6
1b6dc51
17dbcb0
a173eea
4a37e8f
79a49e1
5fb6e54
a8552d8
6eaff2e
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 | ||||
---|---|---|---|---|---|---|
|
@@ -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, …, n - 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.
Suggested change
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. thanks, changed! |
||||||
|
||||||
Returns | ||||||
------- | ||||||
|
@@ -4621,8 +4624,13 @@ 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: | ||||||
if ignore_index: | ||||||
idx = ibase.default_index(len(self[-duplicated])) | ||||||
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 think this block could be more succinctly written as: result = self[~duplicated]
if ignore_index:
result = result.reset_index(drop=True)
return result Or something similar. FWIW I think the current method of evaluating 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. ahh, good call! @WillAyd will change! i think |
||||||
return self[-duplicated].set_index(idx) | ||||||
return self[-duplicated] | ||||||
|
||||||
return None | ||||||
|
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!