Skip to content

BUG: nunique not ignoring both None and np.nan #37566

Closed
@Tomer-Eliahu

Description

@Tomer-Eliahu
  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

import pandas as pd
import numpy as np
pd.Series(['yes','yes', None, np.nan]).nunique(dropna = True)

Problem description

The output was 2.
It seems that nunique can only ignore None or np.nan but not both together. This seems odd to me and I think it
should either be changed or the docs should reflect this.

Expected Output

I expected to get 1 as the result but I got 2.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : db08276
python : 3.7.6.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.49+
Version : #1 SMP Sun Oct 18 19:43:35 PDT 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : C.UTF-8
LANG : C.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.1.3
numpy : 1.18.5
pytz : 2019.3
dateutil : 2.8.1
pip : 20.2.4
setuptools : 46.1.3.post20200325
Cython : 0.29.21
pytest : 5.4.1
hypothesis : 5.10.0
sphinx : 3.0.2
blosc : None
feather : 0.4.1
xlsxwriter : 1.2.8
lxml.etree : 4.5.0
html5lib : 1.0.1
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.13.0
pandas_datareader: 0.9.0
bs4 : 4.9.0
bottleneck : 1.3.2
fsspec : 0.8.4
fastparquet : None
gcsfs : 0.6.1
matplotlib : 3.2.1
numexpr : 2.7.1
odfpy : None
openpyxl : 3.0.3
pandas_gbq : None
pyarrow : 0.16.0
pytables : None
pyxlsb : None
s3fs : 0.5.1
scipy : 1.4.1
sqlalchemy : 1.3.16
tables : 3.6.1
tabulate : 0.8.7
xarray : 0.16.1
xlrd : 1.2.0
xlwt : 1.3.0
numba : 0.48.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolate

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions