ENH: Allow keep='all' for nlargest/nsmallest
State: closed

Title is self-explanatory.

Closes #16818.
Closes #18656.


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

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/21650?src=pr&el=h1) Report
> Merging [#21650](https://codecov.io/gh/pandas-dev/pandas/pull/21650?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/e0f978d43c960e0af7944a9d7d410662e071c0c7?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

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

```diff
@@            Coverage Diff             @@
##           master   #21650      +/-   ##
==========================================
+ Coverage    91.9%    91.9%   +<.01%     
==========================================
  Files         154      154              
  Lines       49555    49557       +2     
==========================================
+ Hits        45542    45544       +2     
  Misses       4013     4013
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.27% <100%> (ø)` | :arrow_up: |
| #single | `42.03% <0%> (ø)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/21650?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/21650/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.19% <ø> (ø)` | :arrow_up: |
| [pandas/core/algorithms.py](https://codecov.io/gh/pandas-dev/pandas/pull/21650/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYWxnb3JpdGhtcy5weQ==) | `94.85% <100%> (+0.01%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/21650?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/21650?src=pr&el=footer). Last update [e0f978d...4998050](https://codecov.io/gh/pandas-dev/pandas/pull/21650?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

@jschendel : Thanks for comments!  TBH, I didn't really check the PR diff before trying to apply it on `master`. 😄  I'll get to these shortly.
@jreback @jschendel : Comments addressed, and all is passing.  PTAL.
Can you add `'all'` to the list of `params` for the `Series` and `DataFrame` asv's related to `NSort`:

https://github.com/pandas-dev/pandas/blob/a620e7255ce896c9185275d82172513268b1a719/asv_bench/benchmarks/series_methods.py#L41-L44

https://github.com/pandas-dev/pandas/blob/a620e7255ce896c9185275d82172513268b1a719/asv_bench/benchmarks/frame_methods.py#L501-L504

I don't think this change will have any perf impact, so no need to run the asv's, but might be nice to have benchmarks in place for this.

LGTM otherwise.
@jschendel : Yep, done.
All is green, so merging.