Skip to content

Series doesn't have an is_unique attribute #11946

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
s-celles opened this issue Jan 3, 2016 · 2 comments
Closed

Series doesn't have an is_unique attribute #11946

s-celles opened this issue Jan 3, 2016 · 2 comments
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Enhancement

Comments

@s-celles
Copy link
Contributor

s-celles 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
Copy link
Contributor

jreback 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 Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff label Jan 3, 2016
@s-celles s-celles changed the title Series doesn't have is a is_unique attribute Series doesn't have is an is_unique attribute Jan 3, 2016
@s-celles s-celles changed the title Series doesn't have is an is_unique attribute Series doesn't have an is_unique attribute Jan 3, 2016
@jreback
Copy link
Contributor

jreback commented Jan 6, 2016

closed by #11948

@jreback jreback closed this as completed Jan 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants