DOC: Use a standard header for all rst files
State: closed

- [x] closes #23952 
- [ ] tests added / passed
- [ ] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ ] whatsnew entry


Labels:
name: Docs

Comments:
Hello @saurav2608! Thanks for submitting the PR.

 - There are no PEP8 issues in the file [`doc/source/conf.py`](https://github.com/saurav2608/pandas/blob/ecba5248d0a4a9d53c376a284cc6106d5860ebfc/doc/source/conf.py) !


# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24086?src=pr&el=h1) Report
> Merging [#24086](https://codecov.io/gh/pandas-dev/pandas/pull/24086?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/940104efc9e708bc93744dfaa36c9492b03b1ca4?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `n/a`.

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

```diff
@@           Coverage Diff           @@
##           master   #24086   +/-   ##
=======================================
  Coverage   42.51%   42.51%           
=======================================
  Files         161      161           
  Lines       51691    51691           
=======================================
  Hits        21975    21975           
  Misses      29716    29716
```

| Flag | Coverage Δ | |
|---|---|---|
| #single | `42.51% <ø> (ø)` | :arrow_up: |


------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24086?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/24086?src=pr&el=footer). Last update [940104e...ecba524](https://codecov.io/gh/pandas-dev/pandas/pull/24086?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/24086?src=pr&el=h1) Report
> Merging [#24086](https://codecov.io/gh/pandas-dev/pandas/pull/24086?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/949b1482422dd88db5d039cf38fc19994737bad2?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `n/a`.

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

```diff
@@           Coverage Diff           @@
##           master   #24086   +/-   ##
=======================================
  Coverage   92.21%   92.21%           
=======================================
  Files         162      162           
  Lines       51723    51723           
=======================================
  Hits        47694    47694           
  Misses       4029     4029
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.61% <ø> (ø)` | :arrow_up: |
| #single | `43.03% <ø> (ø)` | :arrow_up: |


------

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

@saurav2608 will you have time to add the numpy and pandas imports to setup.cfg, remove the others from the header, and add the needed ones to where they are used?
> @FHaase do you want to take a look here?

Once your suggestions are implemented I'm fine with that.

@saurav2608 adding this to `setup.cfg` in the `[flake8-rst]` section should fix most of the F821 issues.
```ini
[flake8-rst]
bootstrap = 
    import numpy as np
    import pandas as pd
...
```
> @saurav2608 will you have time to add the numpy and pandas imports to setup.cfg, remove the others from the header, and add the needed ones to where they are used?

I will definitely complete this. I am traveling for work, but will get this done by tomorrow. 
@datapythonista I assume you want to merge this *before* anything else touches the .rst's themselves?
I don't think we have anything else modifying the `.rst` headers, but if we do would be nice to wait a bit and avoid conflicts in this PR, yes.
@saurav2608 did you push your changes? I still can see all the imports in `header`. The only imports in `header` should be `import numpy as np` and `import pandas as pd`. Thanks!
> @saurav2608 did you push your changes? I still can see all the imports in `header`. The only imports in `header` should be `import numpy as np` and `import pandas as pd`. Thanks!

No I have not pushed it yes. I am making the changes now. 
what I don't understand is why the  `noqa F811` is needed. In `header`, after the `import pandas as pd`, we use `pd` to set options, don't we? And I think for `numpy` we set the seed. So, `F811` shouldn't be raised if the module is being used after the import and before the repeated one, or should it?

CC: @FHaase 
There is another behavior I am unable to understand. This build fails on linting error on the file comparison_with_sql.rst. `comparison_with_sql.rst:17:5: F811 redefinition of unused 'pd' from line 2`. This file does not have the header block (I have not touched this file in this commit). Thus pd is defined for the first time at line 17. Is the `bootstrap` parameter causing F811?
@saurav2608 general note: when updating the PR, can you add new commits instead of amending or squashing with the previous one? That makes it easier to review only the new changes. 
(When the PR is merged, it will be squashed anyway, so it is no problem to have "fixup" commits). 
@saurav2608, if you want you can remove the `noqa`, and if the files are being checked for `flake8-rst` and `ci/code_checks.py` reports errors, you can add the files to the ignore list for `flake8-rst` in `setup.cfg`.

This way we can merge this, avoid conflicts, and we can fix the `flake8-rst` errors in a new PR
@datapythonista, I have removed the #noqa and added the files to the ignore list. I have also added header to all the rst file. 
Sure, will open the issues. 
@datapythonista looks ok. are you sure you wan tthe ``from pandas import *`` in the older release notes? or just not worth it to fix
I think for now makes sense to have the `from pandas import *`, so we can validate the rest of the files for errors (and avoid ignoring them and not validate any error). I guess there won't be many errors, and if that's the case it's probably worth to leave them clean at some point (surely not a priority).
@datapythonista , @jreback : Can you please merge this? I will create follow-up issues for the revised code. 
@saurav2608 pls merge master. @datapythonista ok by me.
@saurav2608 merged the conflict myself, merging on green
Thanks @saurav2608 for taking care of this, good improvement
@saurav2608 I already fixed the errors when importing `import pandas as pd` (and numpy) in the files in #24182, no need to open an issue for those