Skip to content

BUG: nlargest returns empty frame with NA + duplicates #45050

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
LucasG0 opened this issue Dec 24, 2021 · 1 comment
Closed
2 of 3 tasks

BUG: nlargest returns empty frame with NA + duplicates #45050

LucasG0 opened this issue Dec 24, 2021 · 1 comment
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Bug Duplicate Report Duplicate issue or pull request Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate NA - MaskedArrays Related to pd.NA and nullable extension arrays

Comments

@LucasG0
Copy link
Contributor

LucasG0 commented Dec 24, 2021

Pandas version checks

  • I have checked that this issue has not already been reported.

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

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

Reproducible Example

>>> df
   c1   c2
0   1  NaN
1   0  0.0
2   1  NaN
>>> df.nlargest(n=1, columns=["c1", "c2"])
Empty DataFrame
Columns: [c1, c2]
Index: []

Issue Description

The returned DataFrame is empty while it should have one row when rows having NA are duplicated.

Expected Behavior

The first row should be returned, as when the row with NA is not duplicated.

>>> df.iloc[0:2].nlargest(n=1, columns=["c1", "c2"])
   c1  c2
0   1 NaN

Installed Versions

INSTALLED VERSIONS

commit : 66e3805
python : 3.7.6.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19041
machine : AMD64
processor : Intel64 Family 6 Model 142 Stepping 11, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None

pandas : 1.3.5
numpy : 1.19.5
pytz : 2020.1
dateutil : 2.8.1
pip : 20.2.2
setuptools : 49.4.0.post20200813
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.6.0
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : 0.52.0

@LucasG0 LucasG0 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 24, 2021
@LucasG0 LucasG0 changed the title BUG: nlargest with NA + duplicates BUG: nlargest returns empty frame with NA + duplicates Dec 24, 2021
@jbrockmendel jbrockmendel added the NA - MaskedArrays Related to pd.NA and nullable extension arrays label Dec 24, 2021
@mroeschke mroeschke added Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 27, 2021
@phofl
Copy link
Member

phofl commented Dec 29, 2021

This is more or less a duplicate of #28984 and was fixed in #43060. Tests were also added

@phofl phofl closed this as completed Dec 29, 2021
@phofl phofl added this to the No action milestone Dec 29, 2021
@phofl phofl added the Duplicate Report Duplicate issue or pull request label Dec 29, 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 Duplicate Report Duplicate issue or pull request Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate NA - MaskedArrays Related to pd.NA and nullable extension arrays
Projects
None yet
Development

No branches or pull requests

4 participants