ENH: enable Series.info()
State: closed

- [ ] closes #5167
- [ ] tests added / passed
- [ ] passes `black pandas`
- [ ] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ ] whatsnew entry

I took over https://github.com/pandas-dev/pandas/pull/31796 from @MarcoGorelli.
In this PR I took the tests and the docstring from https://github.com/pandas-dev/pandas/pull/31796, refactored tests (separated into dataframe and series-related only test classes).
Then on top of the recent changes (https://github.com/pandas-dev/pandas/pull/36752) I implemented series info.

New classes:
 - ``SeriesInfo`` (store data, which will be used in the outputs)
 - ``SeriesInfoPrinter`` (basically creator of the appropriate table builder)
 - ``SeriesTableBuilder`` (both Verbose and NonVerbose)
 - ``TableBuilderVerboseMixin`` (shared functionality for verbose info builders of both dataframe and series)

It seems to me that tests are not sufficient enough.
In particular, it seems that empty series info should be covered.
Currently there is a special empty dataframe info, but for series info there is just a generic verbose info with zero items.
If there is a need for a dedicated empty series info, then I would need to add method ``_fill_empty_info`` into ``SeriesTableBuilder``.

Static typing makes code quite verbose. In some cases we have the very same methods/properties, but with different type annotations to satisfy type checking (methods are small, but anyway). If somebody can suggest me a better way to handle it, then that would be great.

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

Comments:
Got some CI issue with building documentation (presumably because of warning related to numpy).
I think this is not related to the changes. Can anyone restart?

<details>

In file included from /home/runner/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/numpy/core/include/numpy/ndarraytypes.h:1822:0,
                 from /home/runner/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,
                 from /home/runner/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/numpy/core/include/numpy/arrayobject.h:4,
                 from /home/runner/.cache/ipython/cython/_cython_magic_1e384fc850b1a0be145d9b7384e71f98.c:630:
/home/runner/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
 #warning "Using deprecated NumPy API, disable it with " \
  ^~~~~~~
In file included from /home/runner/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/numpy/core/include/numpy/ndarraytypes.h:1822:0,
                 from /home/runner/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,
                 from /home/runner/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/numpy/core/include/numpy/arrayobject.h:4,
                 from /home/runner/.cache/ipython/cython/_cython_magic_1f3f4faa63381d31bc6688d149dcf218.c:631:
/home/runner/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
 #warning "Using deprecated NumPy API, disable it with " \
  ^~~~~~~

</details>

> Static typing makes code quite verbose. In some cases we have the very same methods/properties, but with different type annotations to satisfy type checking (methods are small, but anyway). If somebody can suggest me a better way to handle it, then that would be great.

we have FrameOrSeries to handle this or FrameOrUnion, otherwise you can make a type alias as well.
> 
> 
> Thanks @ivanovmg for the PR.
> 
> needs a release note in 1.2 and a versionadded tag in Series.info docstring.

I added versionadded tag.
The problem is that it creates extra newline in ``DataFrame.info()`` docstring.
Any idea how to solve this? Like, if substitution string is empty, then do not create new line.

Or maybe it is better to just create two separate docstrings for DataFrame and Series, but with the duplication?
> I added versionadded tag.
> The problem is that it creates extra newline in `DataFrame.info()` docstring.

CI/Checks complains just about that.

@ivanovmg if you'd merge master will have a look
I managed to solve the problem with an extra newline in the docstring if versionadded is not applicable (DataFrame.info).
@jreback @MarcoGorelli @simonjayhawkins is there a plan to add it into milestone 1.2?
> 
> 
> can you do a pre-cursor PR where you just put the dataframe in the proper shape w/o changing tests except trivially.
> 
> Also the docs need to be done generically (docs should be in this file) and not in the core/frame/series (e.g. use the doc decorator).

@jreback can you please clarify?
Do you suggest that I revert changes in ``test_info.py``, which concern dataframes?
So that you can ensure that the old behavior is not changed.

I can do it and then change tests later on, when this PR is merged.
> > can you do a pre-cursor PR where you just put the dataframe in the proper shape w/o changing tests except trivially.
> > Also the docs need to be done generically (docs should be in this file) and not in the core/frame/series (e.g. use the doc decorator).
> 
> @jreback can you please clarify?
> Do you suggest that I revert changes in `test_info.py`, which concern dataframes?
> So that you can ensure that the old behavior is not changed.
> 
> I can do it and then change tests later on, when this PR is merged.

no i suggest you create a new PR that doesn't touch series at all. IOW adjust what you need so its an easy to under stand and clear chnage to any structure and preserves dataframe, while moving the docs to the right place. This is just too much change in a single PR to ensure that you are not changing existing behavior.
OK
This pull request is stale because it has been open for thirty days with no activity. Please update or respond to this comment if you're still interested in working on this.
Going to mark as a draft as this PR depends on https://github.com/pandas-dev/pandas/pull/38062
would take this, if you can merge master and will look
Hello @ivanovmg! Thanks for updating this PR. We checked the lines you've touched for [PEP 8](https://www.python.org/dev/peps/pep-0008) issues, and found:











There are currently no PEP 8 issues detected in this Pull Request. Cheers! :beers: 

##### Comment last updated at 2021-11-30 02:01:11 UTC
@jreback, I merged master and made several updates.
thanks @ivanovmg