Shorter truncated Series/DataFrame repr: introduce min_rows
State: closed

Closes #27000

(didn't yet add tests, docs or whatsnew, but I think the implementation is already more or less complete)


Labels:
name: Output-Formatting
description: __repr__ of pandas objects, to_string

Comments:
@jorisvandenbossche think you'll be able to update in the next 24 hours?
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/27095?src=pr&el=h1) Report
> Merging [#27095](https://codecov.io/gh/pandas-dev/pandas/pull/27095?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/7ab9ff579daebd6b16c357221850f85c7e218d97?src=pr&el=desc) will **decrease** coverage by `49.9%`.
> The diff coverage is `53.33%`.

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

```diff
@@             Coverage Diff             @@
##           master   #27095       +/-   ##
===========================================
- Coverage   91.79%   41.89%   -49.91%     
===========================================
  Files         180      180               
  Lines       50934    50803      -131     
===========================================
- Hits        46757    21286    -25471     
- Misses       4177    29517    +25340
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `?` | |
| #single | `41.89% <53.33%> (-0.22%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/27095?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/27095/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `34.99% <ø> (-61.94%)` | :arrow_down: |
| [pandas/core/series.py](https://codecov.io/gh/pandas-dev/pandas/pull/27095/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc2VyaWVzLnB5) | `45.45% <ø> (-47.06%)` | :arrow_down: |
| [pandas/core/config\_init.py](https://codecov.io/gh/pandas-dev/pandas/pull/27095/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29uZmlnX2luaXQucHk=) | `80.68% <100%> (-15.39%)` | :arrow_down: |
| [pandas/io/formats/format.py](https://codecov.io/gh/pandas-dev/pandas/pull/27095/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvZm9ybWF0LnB5) | `50.57% <46.15%> (-47.35%)` | :arrow_down: |
| [pandas/io/formats/latex.py](https://codecov.io/gh/pandas-dev/pandas/pull/27095/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvbGF0ZXgucHk=) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/io/gcs.py](https://codecov.io/gh/pandas-dev/pandas/pull/27095/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2djcy5weQ==) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/io/sas/sas\_constants.py](https://codecov.io/gh/pandas-dev/pandas/pull/27095/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3Nhcy9zYXNfY29uc3RhbnRzLnB5) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/core/groupby/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/27095/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS9jYXRlZ29yaWNhbC5weQ==) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/tseries/plotting.py](https://codecov.io/gh/pandas-dev/pandas/pull/27095/diff?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvcGxvdHRpbmcucHk=) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/tseries/converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/27095/diff?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvY29udmVydGVyLnB5) | `0% <0%> (-100%)` | :arrow_down: |
| ... and [142 more](https://codecov.io/gh/pandas-dev/pandas/pull/27095/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/27095?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/27095?src=pr&el=footer). Last update [7ab9ff5...98e7d43](https://codecov.io/gh/pandas-dev/pandas/pull/27095?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/27095?src=pr&el=h1) Report
> Merging [#27095](https://codecov.io/gh/pandas-dev/pandas/pull/27095?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/7ab9ff579daebd6b16c357221850f85c7e218d97?src=pr&el=desc) will **decrease** coverage by `49.9%`.
> The diff coverage is `53.33%`.

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

```diff
@@             Coverage Diff             @@
##           master   #27095       +/-   ##
===========================================
- Coverage   91.79%   41.89%   -49.91%     
===========================================
  Files         180      180               
  Lines       50934    50803      -131     
===========================================
- Hits        46757    21286    -25471     
- Misses       4177    29517    +25340
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `?` | |
| #single | `41.89% <53.33%> (-0.22%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/27095?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/27095/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `34.99% <ø> (-61.94%)` | :arrow_down: |
| [pandas/core/series.py](https://codecov.io/gh/pandas-dev/pandas/pull/27095/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc2VyaWVzLnB5) | `45.45% <ø> (-47.06%)` | :arrow_down: |
| [pandas/core/config\_init.py](https://codecov.io/gh/pandas-dev/pandas/pull/27095/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29uZmlnX2luaXQucHk=) | `80.68% <100%> (-15.39%)` | :arrow_down: |
| [pandas/io/formats/format.py](https://codecov.io/gh/pandas-dev/pandas/pull/27095/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvZm9ybWF0LnB5) | `50.57% <46.15%> (-47.35%)` | :arrow_down: |
| [pandas/io/formats/latex.py](https://codecov.io/gh/pandas-dev/pandas/pull/27095/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvbGF0ZXgucHk=) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/io/gcs.py](https://codecov.io/gh/pandas-dev/pandas/pull/27095/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2djcy5weQ==) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/io/sas/sas\_constants.py](https://codecov.io/gh/pandas-dev/pandas/pull/27095/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3Nhcy9zYXNfY29uc3RhbnRzLnB5) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/core/groupby/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/27095/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS9jYXRlZ29yaWNhbC5weQ==) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/tseries/plotting.py](https://codecov.io/gh/pandas-dev/pandas/pull/27095/diff?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvcGxvdHRpbmcucHk=) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/tseries/converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/27095/diff?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvY29udmVydGVyLnB5) | `0% <0%> (-100%)` | :arrow_down: |
| ... and [142 more](https://codecov.io/gh/pandas-dev/pandas/pull/27095/diff?src=pr&el=tree-more) | |

------

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

I added some tests. Further to do:

- Still need to add a whatsnew note / docs
- We can decide to not add the `min_rows` argument to `to_string`, but only in the Series/DataFrameFormatter classes if we want (cc @simonjayhawkins ), by using those Formatter classes directly in `__repr__` instead of calling `to_string` (`to_string` is only brief wrapper around the Formatter classes, so it would not add much code duplication)
> -1 on adding keywords to public methods

As I said above, it is easy to avoid that, *if* we want (with only a little bit of code duplication, just a call to the `Formatter` class. But it also gives some consistency since max_rows and max_cols are there as well.
> > -1 on adding keywords to public methods
> 
> As I said above, it is easy to avoid that, _if_ we want (with only a little bit of code duplication, just a call to the `Formatter` class. But it also gives some consistency since max_rows and max_cols are there as well.

I like the consistency argument here, +1 on adding min_rows to to_string
@jorisvandenbossche doc failure: https://dev.azure.com/pandas-dev/pandas/_build/results?buildId=13946&view=logs&jobId=7e620c85-24a8-5ffa-8b1f-642bc9b1fc36&taskId=2febcae8-7f6a-51bb-45aa-d6e72c9ea7e2&lineStart=2268&lineEnd=2269&colStart=1&colEnd=1

```
/home/vsts/work/1/s/doc/source/whatsnew/v0.25.0.rst:164: WARNING: Inline literal start-string without end-string.
```
Ah, this annoying check we have in our CI ;-)
this is green. any objections?
very nice @jorisvandenbossche