Skip to content
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

Nlargest on boolean return False first #26154

Closed
Wirg opened this issue Apr 19, 2019 · 6 comments

Comments

@Wirg
Copy link

commented Apr 19, 2019

Code Sample, a copy-pastable example if possible

import pandas as pd
pd.Series([True, False]).nlargest(1)

1 False
dtype: bool

Problem description

If you cast this to any other type, you will have the opposite and expected order.
More generally in python True > False. You still have the same order everywhere in pandas.

df = pd.DataFrame({'True': True, 'False': [False] * 2})
df['True'] > df['False']

The result is misleading and can easily lead to a debugging process.

  • Check for duplicate
  • Pandas 0.24.2

Expected Output

1 True
dtype: bool

Output of pd.show_versions()

[paste the output of pd.show_versions() here below this line]
INSTALLED VERSIONS

commit: None
python: 3.6.7.final.0
python-bits: 64
OS: Linux
OS-release: 4.4.0-17763-Microsoft
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: C.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.24.2
pytest: None
pip: 9.0.1
setuptools: 40.6.3
Cython: 0.26.1
numpy: 1.16.2
scipy: 1.1.0
pyarrow: None
xarray: None
IPython: None
sphinx: None
patsy: 0.5.0
dateutil: 2.8.0
pytz: 2019.1
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.2.2
openpyxl: 2.5.8
xlrd: None
xlwt: None
xlsxwriter: 1.1.2
lxml.etree: 4.2.5
bs4: None
html5lib: 0.999999999
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None

@WillAyd

This comment has been minimized.

Copy link
Member

commented Apr 19, 2019

Makes sense. Investigation and PRs are always welcome

@WillAyd WillAyd added the Bug label Apr 19, 2019

@WillAyd WillAyd added this to the Contributions Welcome milestone Apr 19, 2019

@swyoon

This comment has been minimized.

Copy link
Contributor

commented Apr 20, 2019

This is interesting. Let me take a look.

@bpieper26

This comment has been minimized.

Copy link

commented Apr 20, 2019

Looks similar to closed issue #21426. Had a quick today but didn't have time to fix.

@swyoon

This comment has been minimized.

Copy link
Contributor

commented Apr 20, 2019

@bpieper26 Thanks for pointing out. The problem is that a boolean array is converted to a uint array.

@swyoon swyoon referenced this issue Apr 20, 2019

Merged

BUG: Series.nlargest thinks True < False #26157

4 of 4 tasks complete

@gfyoung gfyoung added the Algos label Apr 20, 2019

@Wirg

This comment has been minimized.

Copy link
Author

commented Apr 20, 2019

Thanks for your help :)

@swyoon

This comment has been minimized.

Copy link
Contributor

commented Apr 20, 2019

My pleasure!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.