Skip to content

DOC: pd.Series.nlargest(keep='all') does not ignore duplicates when counting the largest values #45041

Closed
MainHanzo/pandas
#1
@asishm

Description

@asishm

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

In [1]: import pandas as pd

In [3]: s = pd.Series([1,2,3,3,4])
   ...: s.nlargest(2, keep='all')
Out[3]:
4    4
2    3
3    3
dtype: int64

In [4]: s = pd.Series([1,2,3,3,4])
   ...: s.nlargest(3, keep='all')
Out[4]:
4    4
2    3
3    3
dtype: int64

In [5]: pd.__version__
Out[5]: '1.4.0.dev0+1453.ga3c0e7bcfb

Issue Description

nlargest = 2 and nlargest = 3 gives the same output here with keep='all'

Expected Behavior

I'd expect s.nlargest(3, keep='all') to return

4    4
2    3
3    3
1    2
dtype: int64

Installed Versions

INSTALLED VERSIONS ------------------ commit : a3c0e7b python : 3.8.12.final.0 python-bits : 64 OS : Linux OS-release : 4.19.128-microsoft-standard Version : #1 SMP Tue Jun 23 12:58:10 UTC 2020 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : C.UTF-8 LOCALE : en_US.UTF-8

pandas : 1.4.0.dev0+1453.ga3c0e7bcfb
numpy : 1.21.2
pytz : 2021.3
dateutil : 2.8.2
pip : 21.3
setuptools : 58.2.0
Cython : 0.29.24
pytest : 6.2.5
hypothesis : 6.23.2
sphinx : 4.2.0
blosc : None
feather : None
xlsxwriter : 3.0.1
lxml.etree : 4.6.3
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 3.0.2
IPython : 7.28.0
pandas_datareader: None
bs4 : 4.10.0
bottleneck : 1.3.2
fsspec : 2021.10.0
fastparquet : 0.7.1
gcsfs : 2021.10.0
matplotlib : 3.4.3
numexpr : 2.7.3
odfpy : None
openpyxl : 3.0.9
pandas_gbq : None
pyarrow : 5.0.0
pyxlsb : None
s3fs : 2021.10.0
scipy : 1.7.1
sqlalchemy : 1.4.25
tables : 3.6.1
tabulate : 0.8.9
xarray : 0.18.2
xlrd : 2.0.1
xlwt : 1.3.0
numba : 0.53.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions