Skip to content
Merged
Changes from all 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
31 changes: 29 additions & 2 deletions pandas/core/arrays/sparse/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
from pandas.compat.numpy import function as nv
from pandas.errors import PerformanceWarning
from pandas.util._decorators import (
doc,
set_module,
)
from pandas.util._exceptions import find_stack_level
Expand Down Expand Up @@ -885,10 +884,38 @@ def _first_fill_value_loc(self):
diff = np.r_[np.diff(indices), 2]
return indices[(diff > 1).argmax()] + 1

@doc(ExtensionArray.duplicated)
def duplicated(
self, keep: Literal["first", "last", False] = "first"
) -> npt.NDArray[np.bool_]:
"""
Return boolean ndarray denoting duplicate values.

Parameters
----------
keep : {'first', 'last', False}, default 'first'
- ``first`` : Mark duplicates as ``True`` except for the first occurrence.
- ``last`` : Mark duplicates as ``True`` except for the last occurrence.
- False : Mark all duplicates as ``True``.

Returns
-------
ndarray[bool]
With true in indices where elements are duplicated and false otherwise.

See Also
--------
DataFrame.duplicated : Return boolean Series denoting
duplicate rows.
Series.duplicated : Indicate duplicate Series values.
api.extensions.ExtensionArray.unique : Compute the ExtensionArray
of unique values.

Examples
--------
>>> pd.array([1, 1, 2, 3, 3], dtype=pd.SparseDtype(np.int64)).duplicated()
array([False, True, False, False, True])
"""

values = np.asarray(self)
mask = np.asarray(self.isna())
return algos.duplicated(values, keep=keep, mask=mask)
Expand Down
Loading