Skip to content

TST: Difference in drop_duplicates for numeric Series and DataFrames #14192

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
livia-b opened this issue Sep 9, 2016 · 4 comments · Fixed by #14754
Closed

TST: Difference in drop_duplicates for numeric Series and DataFrames #14192

livia-b opened this issue Sep 9, 2016 · 4 comments · Fixed by #14754
Labels
Duplicate Report Duplicate issue or pull request Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Testing pandas testing functions or related to the test suite
Milestone

Comments

@livia-b
Copy link

livia-b commented Sep 9, 2016

Code Sample

import pandas as pd
import numpy as np
df = pd.DataFrame({'a':[1,1,1,'one', 'one'],
                   'b': [2,2,np.nan, np.nan, np.nan],
                   'c': [3,3,np.nan, np.nan, 'three']
                  })
print df[['b']].drop_duplicates() 

print df['b'].drop_duplicates()

Expected Output

Why the result is not consistent?
For a dataframe (first case), the NA values are considered equal (we get 2 unique values), while for a series (second case), the NA values are not (similarly to numpy.unique, we get 3 unique values)

Curiously, in the case of a mixed type column, len(df[['c']].drop_duplicates() ) == len(df['c'].drop_duplicates())

output of pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 2.7.12.final.0
python-bits: 64
OS: Darwin
OS-release: 15.6.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8

pandas: 0.18.1
nose: None
pip: 8.0.3
setuptools: 20.1.1
Cython: 0.23.4
numpy: 1.11.0
scipy: 0.17.1
statsmodels: None
xarray: None
IPython: 4.1.2
sphinx: None
patsy: None
dateutil: 2.5.3
pytz: 2016.4
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 1.5.1
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: 0.9.2
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.8
boto: None
pandas_datareader: None

@jorisvandenbossche
Copy link
Member

Not directly sure where it has been changed/fixed, but I see a consistent return value in master (and 0.19.0rc1):

In [7]: df[['b']].drop_duplicates() 
Out[7]: 
     b
0  2.0
2  NaN

In [8]: df['b'].drop_duplicates()
Out[8]: 
0    2.0
2    NaN
Name: b, dtype: float64

@jorisvandenbossche
Copy link
Member

Would it actually be useful to be able to specify how to treat NaNs?

@livia-b
Copy link
Author

livia-b commented Sep 9, 2016

For my specific application not really (I found this behaviour only because I forgot to use dropna to clean my data) , I am not sure how the other users need to handle it...

@jreback
Copy link
Contributor

jreback commented Sep 9, 2016

I think #13514 solved this, it appears enough tests. but if someone can review, could always add some specific ones for this consistency.

@jreback jreback added Testing pandas testing functions or related to the test suite Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Difficulty Novice labels Sep 9, 2016
@jreback jreback added this to the Next Major Release milestone Sep 9, 2016
@jreback jreback added the Duplicate Report Duplicate issue or pull request label Sep 9, 2016
@jreback jreback changed the title Difference in drop_duplicates for numeric Series and DataFrames TST: Difference in drop_duplicates for numeric Series and DataFrames Sep 9, 2016
mroeschke added a commit to mroeschke/pandas that referenced this issue Dec 2, 2016
@jorisvandenbossche jorisvandenbossche modified the milestones: 0.20.0, Next Major Release Dec 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants