diff --git a/doc/source/api.rst b/doc/source/api.rst index 3c7ca6d5c2326..98279fbbe6796 100644 --- a/doc/source/api.rst +++ b/doc/source/api.rst @@ -345,6 +345,7 @@ Computations / Descriptive Stats Series.var Series.unique Series.nunique + Series.is_unique Series.value_counts Reindexing / Selection / Label manipulation diff --git a/doc/source/whatsnew/v0.18.0.txt b/doc/source/whatsnew/v0.18.0.txt index 2c97cae80ae2a..d446bf2dd1977 100644 --- a/doc/source/whatsnew/v0.18.0.txt +++ b/doc/source/whatsnew/v0.18.0.txt @@ -108,6 +108,7 @@ Other enhancements - A simple version of ``Panel.round()`` is now implemented (:issue:`11763`) - For Python 3.x, ``round(DataFrame)``, ``round(Series)``, ``round(Panel)`` will work (:issue:`11763`) - ``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`) +- ``Series`` have an ``is_unique`` attribute (:issue:`11946`) .. _whatsnew_0180.enhancements.rounding: diff --git a/pandas/core/base.py b/pandas/core/base.py index a1e1c20344ea4..cb29ab11dd34e 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -797,6 +797,17 @@ def nunique(self, dropna=True): n -= 1 return n + @property + def is_unique(self): + """ + Return if values in the object are unique or not. + + Returns + ------- + is_unique : bool + """ + return self.nunique() == len(self) + def memory_usage(self, deep=False): """ Memory usage of my values diff --git a/pandas/tests/test_series.py b/pandas/tests/test_series.py index ad79406c70704..c8a4b1d1ae924 100644 --- a/pandas/tests/test_series.py +++ b/pandas/tests/test_series.py @@ -1,4 +1,4 @@ -# coding=utf-8 +# coding=utf-8 # pylint: disable-msg=E1101,W0612 import re @@ -8205,6 +8205,12 @@ class SubclassedFrame(DataFrame): expected = SubclassedFrame({'X': [1, 2, 3]}) assert_frame_equal(result, expected) + def test_is_unique(self): + # GH11946 + s = Series(np.random.randint(0,10,size=1000)) + self.assertFalse(s.is_unique) + s = Series(np.arange(1000)) + self.assertTrue(s.is_unique) class TestSeriesNonUnique(tm.TestCase):