Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.23.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Performance Improvements
~~~~~~~~~~~~~~~~~~~~~~~~

- Improved performance of :meth:`CategoricalIndex.is_monotonic_increasing`, :meth:`CategoricalIndex.is_monotonic_decreasing` and :meth:`CategoricalIndex.is_monotonic` (:issue:`21025`)
- Improved performance of :meth:`CategoricalIndex.is_unique` (:issue:`21107`)
-
-

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def _engine(self):
# introspection
@cache_readonly
def is_unique(self):
return not self.duplicated().any()
return self._engine.is_unique

@property
def is_monotonic_increasing(self):
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/indexes/test_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,15 @@ def test_is_monotonic(self, data, non_lexsorted_data):
assert c.is_monotonic_increasing
assert not c.is_monotonic_decreasing

@pytest.mark.parametrize('values, expected', [
([1, 2, 3], True),
([1, 3, 1], False),
(list('abc'), True),
(list('aba'), False)])
def test_is_unique(self, values, expected):
ci = CategoricalIndex(values)
assert ci.is_unique is expected

def test_duplicates(self):

idx = CategoricalIndex([0, 0, 0], name='foo')
Expand Down