added option keep=False to nlargests/nsmallest
State: closed

- [x] closes #16818
- [x] tests added / passed
- [ ] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ ] whatsnew entry

I made a minor change to `nlargest/nsmallest` to keep all the values of the last `n` when `keep=False`

Labels:
name: API Design
name: Algos
description: Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff

Comments:
Closed due to decision in #18559.
actually this is prob reasonable.
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/18656?src=pr&el=h1) Report
> Merging [#18656](https://codecov.io/gh/pandas-dev/pandas/pull/18656?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/13f6267207dd1f140b12d7718277508eff5c1efb?src=pr&el=desc) will **decrease** coverage by `0.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/18656/graphs/tree.svg?token=eZ4WkYLtcO&width=650&src=pr&height=150)](https://codecov.io/gh/pandas-dev/pandas/pull/18656?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #18656      +/-   ##
==========================================
- Coverage   91.59%   91.57%   -0.02%     
==========================================
  Files         153      153              
  Lines       51221    51223       +2     
==========================================
- Hits        46917    46910       -7     
- Misses       4304     4313       +9
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.44% <100%> (ø)` | :arrow_up: |
| #single | `40.67% <0%> (-0.11%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/18656?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/algorithms.py](https://codecov.io/gh/pandas-dev/pandas/pull/18656/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYWxnb3JpdGhtcy5weQ==) | `94.16% <100%> (+0.01%)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/18656/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/18656/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.81% <0%> (-0.1%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/18656?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/18656?src=pr&el=footer). Last update [13f6267...fcfc563](https://codecov.io/gh/pandas-dev/pandas/pull/18656?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/18656?src=pr&el=h1) Report
> Merging [#18656](https://codecov.io/gh/pandas-dev/pandas/pull/18656?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/265e3272b8709a7be274321ee8b505a0e74b8e10?src=pr&el=desc) will **decrease** coverage by `0.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/18656/graphs/tree.svg?height=150&width=650&token=eZ4WkYLtcO&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/18656?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #18656      +/-   ##
==========================================
- Coverage   91.61%    91.6%   -0.02%     
==========================================
  Files         153      153              
  Lines       51367    51369       +2     
==========================================
- Hits        47061    47056       -5     
- Misses       4306     4313       +7
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.46% <100%> (ø)` | :arrow_up: |
| #single | `40.76% <0%> (-0.12%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/18656?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/18656/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.81% <ø> (-0.1%)` | :arrow_down: |
| [pandas/core/algorithms.py](https://codecov.io/gh/pandas-dev/pandas/pull/18656/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYWxnb3JpdGhtcy5weQ==) | `94.16% <100%> (+0.01%)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/18656/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/18656/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `82.52% <0%> (+0.19%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/18656?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/18656?src=pr&el=footer). Last update [265e327...56954b4](https://codecov.io/gh/pandas-dev/pandas/pull/18656?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

@jreback : What do you think of making `keep=False` be the option?  Besides API consistency, semantically, it doesn't make as much sense to me (or @tdpetrou ) to use because it would imply that we drop ties.
@jreback As @gfyoung mentioned, can we choose the parameter value first before making more changes. Should we do 'all', `False`, or something completely different?

edit: I am highly in favor of 'all'
yeah ``False`` doesn't seem intuitive, ``all`` I think would be ok. Not sure if we have this option anywhere else (e.g. it doesn't exist in ``.drop_duplicates`` nor should it as that would be silly:>)
@jreback Changes complete. Also, I didn't see anything in whatsnew on the other issues.
pls rebase
closing as stale
@jreback : Revived in #21650.