-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH: Allow Iterable[Hashable] in drop_duplicates #59392
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
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
39cb4ca
ENH: pandas-dev#59237
kirill-bash 03c33ee
adding whatsnew note
kirill-bash 4ff6206
updates based on feedback
kirill-bash 6e7f1b1
updates based on feedback: Sequence[Hashable] -> Iterable[Hashable]
kirill-bash e43ca96
adding whatsnew note
kirill-bash 68e6e13
set is part of Iterable[Hashable]
kirill-bash 77ff9e6
removing type: ignore[assignment]
kirill-bash cd959d4
Merge branch 'main' into main
kirill-bash f74c9f4
Remove remaining comment
rhshadrach 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,6 @@ | |
Iterator, | ||
Mapping, | ||
Sequence, | ||
Set as AbstractSet, | ||
) | ||
import functools | ||
from io import StringIO | ||
|
@@ -6405,7 +6404,7 @@ def dropna( | |
|
||
thresh : int, optional | ||
Require that many non-NA values. Cannot be combined with how. | ||
subset : column label or sequence of labels, optional | ||
subset : column label or iterable of labels, optional | ||
Labels along other axis to consider, e.g. if you are dropping rows | ||
these would be a list of columns to include. | ||
inplace : bool, default False | ||
|
@@ -6535,7 +6534,7 @@ def dropna( | |
@overload | ||
def drop_duplicates( | ||
self, | ||
subset: Hashable | Sequence[Hashable] | AbstractSet | None = ..., | ||
subset: Hashable | Iterable[Hashable] | set | None = ..., | ||
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. No need for 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. That's true. Updated. |
||
*, | ||
keep: DropKeep = ..., | ||
inplace: Literal[True], | ||
|
@@ -6545,7 +6544,7 @@ def drop_duplicates( | |
@overload | ||
def drop_duplicates( | ||
self, | ||
subset: Hashable | Sequence[Hashable] | AbstractSet | None = ..., | ||
subset: Hashable | Iterable[Hashable] | set | None = ..., | ||
*, | ||
keep: DropKeep = ..., | ||
inplace: Literal[False] = ..., | ||
|
@@ -6555,7 +6554,7 @@ def drop_duplicates( | |
@overload | ||
def drop_duplicates( | ||
self, | ||
subset: Hashable | Sequence[Hashable] | AbstractSet | None = ..., | ||
subset: Hashable | Iterable[Hashable] | set | None = ..., | ||
*, | ||
keep: DropKeep = ..., | ||
inplace: bool = ..., | ||
|
@@ -6564,7 +6563,7 @@ def drop_duplicates( | |
|
||
def drop_duplicates( | ||
self, | ||
subset: Hashable | Sequence[Hashable] | AbstractSet | None = None, | ||
subset: Hashable | Iterable[Hashable] | set | None = None, | ||
*, | ||
keep: DropKeep = "first", | ||
inplace: bool = False, | ||
|
@@ -6578,7 +6577,7 @@ def drop_duplicates( | |
|
||
Parameters | ||
---------- | ||
subset : column label or sequence of labels, optional | ||
subset : column label or iterable of labels, optional | ||
Only consider certain columns for identifying duplicates, by | ||
default use all of the columns. | ||
keep : {'first', 'last', ``False``}, default 'first' | ||
|
@@ -6668,7 +6667,7 @@ def drop_duplicates( | |
|
||
def duplicated( | ||
self, | ||
subset: Hashable | Sequence[Hashable] | AbstractSet | None = None, | ||
subset: Hashable | Iterable[Hashable] | set | None = None, | ||
keep: DropKeep = "first", | ||
) -> Series: | ||
""" | ||
|
@@ -6678,7 +6677,7 @@ def duplicated( | |
|
||
Parameters | ||
---------- | ||
subset : column label or sequence of labels, optional | ||
subset : column label or iterable of labels, optional | ||
Only consider certain columns for identifying duplicates, by | ||
default use all of the columns. | ||
keep : {'first', 'last', False}, default 'first' | ||
|
@@ -6793,13 +6792,8 @@ def f(vals) -> tuple[np.ndarray, int]: | |
raise KeyError(Index(diff)) | ||
|
||
if len(subset) == 1 and self.columns.is_unique: | ||
# GH#59237 adding support for single element sets | ||
if isinstance(subset, set): | ||
elem = subset.pop() | ||
else: | ||
elem = subset[0] | ||
# GH#45236 This is faster than get_group_index below | ||
result = self[elem].duplicated(keep) | ||
result = self[next(iter(subset))].duplicated(keep) | ||
result.name = None | ||
else: | ||
vals = (col.values for name, col in self.items() if name in subset) | ||
|
Oops, something went wrong.
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.
Same here - can remove
Set
now.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.
Updated. Thanks!