Skip to content

BUG: 1.3.0rc Series.mode errors with BooleanDtype series containing nans #42107

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
2 of 3 tasks
tamargrey opened this issue Jun 18, 2021 · 2 comments · Fixed by #42131
Closed
2 of 3 tasks

BUG: 1.3.0rc Series.mode errors with BooleanDtype series containing nans #42107

tamargrey opened this issue Jun 18, 2021 · 2 comments · Fixed by #42131
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Bug Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@tamargrey
Copy link

  • 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.


Code Sample, a copy-pastable example

import pandas as pd

pd.Series([True, False, True, pd.NA], dtype='boolean').mode()

Problem description

The above mode call produces the following error: TypeError: int() argument must be a string, a bytes-like object or a number, not 'NAType'.

This occurs whether pd.NA or None or np.nan is used.

Expected Output

The mode call should not raise an error.

assert pd.Series([True, False, True, pd.NA], dtype='boolean').mode() is True

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 2dd9e9b
python : 3.8.2.final.0
python-bits : 64
OS : Darwin
OS-release : 19.6.0
Version : Darwin Kernel Version 19.6.0: Sun Jul 5 00:43:10 PDT 2020; root:xnu-6153.141.1~9/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.3.0rc1
numpy : 1.20.3
pytz : 2021.1
dateutil : 2.8.1
pip : 21.1.2
setuptools : 41.2.0
Cython : None
pytest : 6.0.1
hypothesis : None
sphinx : 3.2.1
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.3
IPython : 7.18.1
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : 2021.06.0
fastparquet : 0.5.0
gcsfs : None
matplotlib : 3.2.2
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 4.0.1
pyxlsb : None
s3fs : None
scipy : 1.6.3
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : 0.53.1

@tamargrey tamargrey added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 18, 2021
@tamargrey tamargrey changed the title BUG: Series.mode errors with BooleanDtype series containing nans BUG: 1.3.0rc Series.mode errors with BooleanDtype series containing nans Jun 18, 2021
simonjayhawkins added a commit to simonjayhawkins/pandas that referenced this issue Jun 19, 2021
@simonjayhawkins
Copy link
Member

Thanks @tamargrey for the report

The above mode call produces the following error: TypeError: int() argument must be a string, a bytes-like object or a number, not 'NAType'.

first bad commit: [b4375a4] REF: avoid unnecessary casting in algorithms (#41256) cc @jbrockmendel

Expected Output

The mode call should not raise an error.

assert pd.Series([True, False, True, pd.NA], dtype='boolean').mode() is True

The expected output is a Series, see https://pandas.pydata.org/pandas-docs/dev/reference/api/pandas.Series.mode.html

0    True
dtype: boolean

@simonjayhawkins
Copy link
Member

Thanks @tamargrey for the report

and thanks for testing the rc!

@simonjayhawkins simonjayhawkins added Regression Functionality that used to work in a prior pandas version and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 19, 2021
@simonjayhawkins simonjayhawkins added this to the 1.3 milestone Jun 19, 2021
@lithomas1 lithomas1 added the Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff label Jun 19, 2021
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 Bug Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants