BUG: Inconsistent results of value_counts and mode for different nan-values · Issue #39007 · pandas-dev/pandas (original) (raw)

import pandas as pd import numpy as np s=pd.Series([True, pd.NA, np.nan]) s.value_counts(dropna=False) print(s.value_counts(dropna=False)) print(s.mode(dropna=False))

Problem description

For s.value_counts(...) the result is

NaN     2
True    1
dtype: int64

but for s.mode(...) the output is:

0     NaN
1    True
2    <NA>
dtype: object

Expected Output

for the sake of consistancy one would expect mode to be only NaN, as it was counted twice with value_counts, i.e.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : b5958ee
python : 3.7.3.final.0
python-bits : 64
OS : Linux
OS-release : 4.4.0-53-generic
Version : #74-Ubuntu SMP Fri Dec 2 15:59:10 UTC 2016
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.1.5
numpy : 1.19.2
pytz : 2020.5
dateutil : 2.8.1
pip : 20.3.3
setuptools : 51.0.0.post20201207
Cython : 0.29.21
pytest : 5.4.3
hypothesis : 5.36.0
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.19.0
pandas_datareader: None
bs4 : 4.9.3
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.3.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.2.1
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : 0.50.1