Skip to content

ENH: add is_unique attr to Series #11948

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 1 commit into from
Closed
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/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ Computations / Descriptive Stats
Series.var
Series.unique
Series.nunique
Series.is_unique
Series.value_counts

Reindexing / Selection / Label manipulation
Expand Down
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.18.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
11 changes: 11 additions & 0 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion pandas/tests/test_series.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# coding=utf-8
# coding=utf-8
# pylint: disable-msg=E1101,W0612

import re
Expand Down Expand Up @@ -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):

Expand Down