Skip to content

Commit 816a51f

Browse files
s-cellesjreback
authored andcommitted
ENH: add is_unique attr to Series, #11946
1 parent 1dc78c7 commit 816a51f

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

doc/source/api.rst

+1
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ Computations / Descriptive Stats
345345
Series.var
346346
Series.unique
347347
Series.nunique
348+
Series.is_unique
348349
Series.value_counts
349350

350351
Reindexing / Selection / Label manipulation

doc/source/whatsnew/v0.18.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ Other enhancements
110110
- ``DataFrame`` has gained a ``_repr_latex_`` method in order to allow for automatic conversion to latex in a ipython/jupyter notebook using nbconvert. Options ``display.latex.escape`` and ``display.latex.longtable`` have been added to the configuration and are used automatically by the ``to_latex`` method. (:issue:`11778`)
111111
- ``sys.getsizeof(obj)`` returns the memory usage of a pandas object, including the
112112
values it contains (:issue:`11597`)
113+
- ``Series`` gained an ``is_unique`` attribute (:issue:`11946`)
113114

114115
.. _whatsnew_0180.enhancements.rounding:
115116

pandas/core/base.py

+11
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,17 @@ def nunique(self, dropna=True):
832832
n -= 1
833833
return n
834834

835+
@property
836+
def is_unique(self):
837+
"""
838+
Return boolean if values in the object are unique
839+
840+
Returns
841+
-------
842+
is_unique : boolean
843+
"""
844+
return self.nunique() == len(self)
845+
835846
def memory_usage(self, deep=False):
836847
"""
837848
Memory usage of my values

pandas/tests/test_series.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# coding=utf-8
1+
# coding=utf-8
22
# pylint: disable-msg=E1101,W0612
33

44
import re
@@ -8205,6 +8205,13 @@ class SubclassedFrame(DataFrame):
82058205
expected = SubclassedFrame({'X': [1, 2, 3]})
82068206
assert_frame_equal(result, expected)
82078207

8208+
def test_is_unique(self):
8209+
# GH11946
8210+
s = Series(np.random.randint(0, 10, size=1000))
8211+
self.assertFalse(s.is_unique)
8212+
s = Series(np.arange(1000))
8213+
self.assertTrue(s.is_unique)
8214+
82088215

82098216
class TestSeriesNonUnique(tm.TestCase):
82108217

0 commit comments

Comments
 (0)