Skip to content
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

Series doesn't have an is_unique attribute #11946

Closed
scls19fr opened this issue Jan 3, 2016 · 2 comments

Comments

Projects
None yet
2 participants
@scls19fr
Copy link
Contributor

commented Jan 3, 2016

Hello,

Series doesn't have is a is_unique attribute

Index have a is_unique attribute but not (values of a) Series

>>> df.index.is_unique
True

>>> df['Column1'].is_unique
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-417-c450d4c4ceda> in <module>()
----> 1 df['Date'].is_unique

//anaconda/envs/py27/lib/python2.7/site-packages/pandas/core/generic.pyc in __getattr__(self, name)
   2358                 return self[name]
   2359             raise AttributeError("'%s' object has no attribute '%s'" %
-> 2360                                  (type(self).__name__, name))
   2361
   2362     def __setattr__(self, name, value):

AttributeError: 'Series' object has no attribute 'is_unique'

I'm doing this

def is_unique(ser):
    return len(np.unique(ser.values)) == len(ser.values)

but this kind of attribute could be useful when you want to set a column as index and ensure that there is no duplicate keys.

PS: I know there is

    df.set_index('Column1', verify_integrity=True)
@jreback

This comment has been minimized.

Copy link
Contributor

commented Jan 3, 2016

.nunique() and .unique() already exist on a Series, so no need to hand-roll.

I suppose .is_unique could be defined as the below.

want to do a PR?

In [9]: s = Series(np.random.randint(0,10,size=1000))

In [10]: s.nunique() == len(s)
Out[10]: False

In [11]: s = Series(np.arange(1000))

In [12]: s.nunique() == len(s)
Out[12]: True

@jreback jreback added this to the Next Major Release milestone Jan 3, 2016

@jreback jreback added the Algos label Jan 3, 2016

@scls19fr scls19fr changed the title Series doesn't have is a is_unique attribute Series doesn't have is an is_unique attribute Jan 3, 2016

@scls19fr scls19fr changed the title Series doesn't have is an is_unique attribute Series doesn't have an is_unique attribute Jan 3, 2016

jreback added a commit that referenced this issue Jan 6, 2016

@jreback

This comment has been minimized.

Copy link
Contributor

commented Jan 6, 2016

closed by #11948

@jreback jreback closed this Jan 6, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.