Skip to content

TYP: Update input of core.algorithms.duplicated #42657

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

Closed
wants to merge 3 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
)
from pandas.core.arrays import (
DatetimeArray,
ExtensionArray,
TimedeltaArray,
)

Expand Down Expand Up @@ -903,7 +904,8 @@ def value_counts_arraylike(values, dropna: bool):


def duplicated(
values: ArrayLike, keep: Literal["first", "last", False] = "first"
values: np.ndarray | ExtensionArray | Series,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ArrayLike is a alias for np.ndarray | ExtensionArray and can union aliases with other types

Suggested change
values: np.ndarray | ExtensionArray | Series,
values: ArrayLike | Series,

AnyArrayLike also includes Index (as well as Series). Is an Index not a valid type here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@simonjayhawkins
Thanks for the review!

AnyArrayLike also includes Index (as well as Series). Is an Index not a valid type here?
I checked index type and it seems duplicated function accepts one.

import pandas as pd
from pandas.core.algorithms import duplicated
index = pd.Index([1,2,3,4,2,3,1])
duplicated(index)

>> array([False, False, False, False,  True,  True,  True])

Maybe it will be like this?

Suggested change
values: np.ndarray | ExtensionArray | Series,
values: AnyArrayLike,

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. can you also update the parameters section of the docsting.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! I have pushed the code with those change as well!

keep: Literal["first", "last", False] = "first",
) -> np.ndarray:
"""
Return boolean ndarray denoting duplicate values.
Expand Down