Repository: pandas-dev/pandas
Pull request: DOC: Use a standard header for all rst files
- [x] closes #23952 
- [ ] tests added / passed
- [ ] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ ] whatsnew entry


Problem statement:
DOC: Use a standard header for all rst files
When we build the documentation from the `.rst` files in `doc/source/`, we use a variable `common_imports` that is added as context for sphinx, and that is used in the `whatsnew` files.

But more or less the same imports and options that are used in the `whatsnew` files, are used in most `.rst` files.

What would be useful is:
- Rename `common_imports` to `header`, as this will be used for other things in the future (like defining `tocdepth`)
- Add it at the beginning of all the `.rst` files in the same way as it's done for the `whatsnew` files
- Remove the equivalent code already at the beginning of the files
- If there is anything that would be useful to add to the content of `common_imports` (because it's used in many files), add it

This can have implications on the `flake8-rst` validation, as I assume the content is validated before rendering, and the imports will be missing during the validation.

CC: @TomAugspurger @FHaase

Hints from issue discussion:
If the contents are the same throughout each file, they can be supplied via `bootstrap` option.
I am claiming this. 
I understand what is required to complete this. But, how should I do the PR? This will require changing about 50 .rst files under 'whatsnew' and another 50 files in doc/source. Given that there are so many files involved, touching all of them would lead to conflicts. I am outlining proposed steps below - 

1. Change the variable `common_imports` to `headers` in conf.py and update all the `whatsnew` files to use this new variable instead of `common_imports`. 
2. Create a superset of all imports across all the rst files. (Note: this list should include the generic imports. Any special imports should remain in the respective .rst files closer to place they are referred. 
3. Move this superset to the `headers` variable in conf.py. 
4. Remove the top header from all rst files, retaining the special imports. 

Let me know your thoughts. I think steps 1&2 can be clubbed into one PR. 

Feel free to do it in more than one PR, that's all right. But I wouldn't worry much about conflicts, they are not so likely to happen, as the changes to the files will be very small. And if in some case someone is cleaning that rst file and reorder the imports (that's the main thing that could generate a conflict), it should be quite easy to fix. Besides that, I'll try to merge it asap.

Just to be clear, if I'm not missing anything, the PR should mainly replace in all rst files:
```
.. currentmodule:: pandas
  
.. ipython:: python
    :suppress:
  
    import numpy as np
    import pandas as pd
    np.set_printoptions(precision=4, suppress=True)
    pd.options.display.max_rows = 15
```
by
```
{{ header }}
```

But as said, feel free to open more than one PR if that makes sense to you.
@saurav2608 we just merged few changes in rst pages, if you can update the copy of pandas you're working with, I think that will prevent any possible conflict with the changes already done (and I don't think there will be more before merging your PR).
This change introduces additional bunch of erros on `LINT=1 ./ci/code_checks.sh` of the type `F821 undefined name 'pd'`
I think you need to update the version of `flake8-rst`.
Add `--bootstrap='import numpy as np; import pandas as pd'` in `./ci/code-checks.sh`
We have it in the header, and the header is used in all the files, I don't think that should be necessary, right? Doesn't `flake8-rst 0.7` merges all the blocks, including the first one with the header?
Oh, sorry, just realized that `flake8-rst` is not rendering the header with its content, I forgot about it.

@FHaase can the bootstrap argument be added to `setup.cfg`, or should it be in the call?

@saurav2608 for the other imports failing, there are not many, and I think if you import `StringIO`... in the first block where there are used, just with few imports they should all be fixed. Do you mind doing that in the same PR?

Commit message: DOC: Use standard header for .rst files

Patch to review:
diff --git a/doc/source/10min.rst b/doc/source/10min.rst
index e04a8253e0bef..53618e008a403 100644
--- a/doc/source/10min.rst
+++ b/doc/source/10min.rst
@@ -1,24 +1,6 @@
 .. _10min:
 
-.. currentmodule:: pandas
-
-.. ipython:: python
-   :suppress:
-
-   import os
-   import numpy as np
-
-   import pandas as pd
-
-   np.random.seed(123456)
-   np.set_printoptions(precision=4, suppress=True)
-   pd.options.display.max_rows = 15
-
-   # portions of this were borrowed from the
-   # Pandas cheatsheet
-   # created during the PyData Workshop-Sprint 2012
-   # Hannah Chen, Henry Chow, Eric Cox, Robert Mauriello
-
+{{ header }}
 
 ********************
 10 Minutes to pandas
@@ -773,6 +755,7 @@ CSV
 .. ipython:: python
    :suppress:
 
+   import os
    os.remove('foo.csv')
 
 HDF5
diff --git a/doc/source/advanced.rst b/doc/source/advanced.rst
index 39082ef7a4c69..822c9d4faba26 100644
--- a/doc/source/advanced.rst
+++ b/doc/source/advanced.rst
@@ -1,15 +1,6 @@
 .. _advanced:
 
-.. currentmodule:: pandas
-
-.. ipython:: python
-   :suppress:
-
-   import numpy as np
-   import pandas as pd
-   np.random.seed(123456)
-   np.set_printoptions(precision=4, suppress=True)
-   pd.options.display.max_rows = 15
+{{ header }}
 
 ******************************
 MultiIndex / Advanced Indexing
diff --git a/doc/source/basics.rst b/doc/source/basics.rst
index 25e2c8cd1ff9a..dfb8764b5c8e8 100644
--- a/doc/source/basics.rst
+++ b/doc/source/basics.rst
@@ -1,16 +1,7 @@
-.. currentmodule:: pandas
-
-.. ipython:: python
-   :suppress:
-
-   import numpy as np
-   import pandas as pd
-
-   np.set_printoptions(precision=4, suppress=True)
-   pd.options.display.max_rows = 15
-
 .. _basics:
 
+{{ header }}
+
 ==============================
  Essential Basic Functionality
 ==============================
diff --git a/doc/source/categorical.rst b/doc/source/categorical.rst
index 31f2430e4be88..e57fd0ac0f96d 100644
--- a/doc/source/categorical.rst
+++ b/doc/source/categorical.rst
@@ -1,16 +1,6 @@
 .. _categorical:
 
-.. currentmodule:: pandas
-
-.. ipython:: python
-   :suppress:
-
-   import numpy as np
-   import pandas as pd
-   np.random.seed(123456)
-   np.set_printoptions(precision=4, suppress=True)
-   pd.options.display.max_rows = 15
-
+{{ header }}
 
 ****************
 Categorical Data
diff --git a/doc/source/comparison_with_r.rst b/doc/source/comparison_with_r.rst
index 704b0c4d80537..a0143d717105c 100644
--- a/doc/source/comparison_with_r.rst
+++ b/doc/source/comparison_with_r.rst
@@ -1,12 +1,6 @@
-.. currentmodule:: pandas
 .. _compare_with_r:
 
-.. ipython:: python
-   :suppress:
-
-   import pandas as pd
-   import numpy as np
-   pd.options.display.max_rows = 15
+{{ header }}
 
 Comparison with R / R libraries
 *******************************
diff --git a/doc/source/comparison_with_sas.rst b/doc/source/comparison_with_sas.rst
index c4d121c10538c..abc1edd6f6385 100644
--- a/doc/source/comparison_with_sas.rst
+++ b/doc/source/comparison_with_sas.rst
@@ -14,8 +14,8 @@ As is customary, we import pandas and NumPy as follows:
 
 .. ipython:: python
 
-    import pandas as pd
-    import numpy as np
+    import pandas as pd    # noqa: F811
+    import numpy as np     # noqa: F811
 
 
 .. note::
diff --git a/doc/source/computation.rst b/doc/source/computation.rst
index 251dce5141ea5..e72662be7730b 100644
--- a/doc/source/computation.rst
+++ b/doc/source/computation.rst
@@ -1,21 +1,7 @@
-.. currentmodule:: pandas
-
-.. ipython:: python
-   :suppress:
-
-   import numpy as np
-   import matplotlib.pyplot as plt
-
-   import pandas as pd
-
-   np.random.seed(123456)
-   np.set_printoptions(precision=4, suppress=True)
-   pd.options.display.max_rows = 15
-
-   plt.close('all')
-
 .. _computation:
 
+{{ header }}
+
 Computational tools
 ===================
 
diff --git a/doc/source/conf.py b/doc/source/conf.py
index d88b5e9757423..56f77f667df88 100644
--- a/doc/source/conf.py
+++ b/doc/source/conf.py
@@ -301,25 +301,25 @@
 }
 
 
-common_imports = """\
+header = """\
 .. currentmodule:: pandas
 
 .. ipython:: python
    :suppress:
 
    import numpy as np
-   from pandas import *
    import pandas as pd
+
    randn = np.random.randn
+   np.random.seed(123456)
    np.set_printoptions(precision=4, suppress=True)
-   options.display.max_rows = 15
-   from pandas.compat import StringIO
+   pd.options.display.max_rows = 15
 """
 
 
 html_context = {
     'redirects': {old: new for old, new in moved_api_pages},
-    'common_imports': common_imports,
+    'header': header
 }
 
 # If false, no module index is generated.
diff --git a/doc/source/contributing.rst b/doc/source/contributing.rst
index c55452cf27309..83581d0258ed3 100644
--- a/doc/source/contributing.rst
+++ b/doc/source/contributing.rst
@@ -672,6 +672,7 @@ Otherwise, you need to do it manually:
 
     import warnings
 
+
     def old_func():
         """Summary of the function.
 
@@ -681,6 +682,7 @@ Otherwise, you need to do it manually:
         warnings.warn('Use new_func instead.', FutureWarning, stacklevel=2)
         new_func()
 
+
     def new_func():
         pass
 
@@ -814,9 +816,8 @@ We would name this file ``test_cool_feature.py`` and put in an appropriate place
 .. code-block:: python
 
    import pytest
-   import numpy as np
-   import pandas as pd
-   from pandas.util import testing as tm
+   import numpy as np        # noqa: F811
+   import pandas as pd       # noqa: F811
 
 
    @pytest.mark.parametrize('dtype', ['int8', 'int16', 'int32', 'int64'])
@@ -938,8 +939,10 @@ If your change involves checking that a warning is actually emitted, use
 
 .. code-block:: python
 
-   df = pd.DataFrame()
+   import pandas.util.testing as tm
 
+
+   df = pd.DataFrame()
    with tm.assert_produces_warning(FutureWarning):
        df.some_operation()
 
diff --git a/doc/source/cookbook.rst b/doc/source/cookbook.rst
index 16d756acaca51..1b2e856e979a8 100644
--- a/doc/source/cookbook.rst
+++ b/doc/source/cookbook.rst
@@ -1,25 +1,6 @@
 .. _cookbook:
 
-.. currentmodule:: pandas
-
-.. ipython:: python
-   :suppress:
-
-   import datetime
-   import functools
-   import glob
-   import itertools
-   import os
-
-   import numpy as np
-   import pandas as pd
-   from pandas.compat import StringIO
-
-
-   np.random.seed(123456)
-   np.set_printoptions(precision=4, suppress=True)
-   pd.options.display.max_rows = 15
-
+{{ header }}
 
 ********
 Cookbook
@@ -186,6 +167,8 @@ One could hard code:
 
 .. ipython:: python
 
+   import functools
+
    CritList = [Crit1, Crit2, Crit3]
    AllCrit = functools.reduce(lambda x, y: x & y, CritList)
 
@@ -409,6 +392,8 @@ To take the cross section of the 1st level and 1st axis the index:
 
 .. ipython:: python
 
+   import itertools
+
    index = list(itertools.product(['Ada', 'Quinn', 'Violet'],
                                   ['Comp', 'Math', 'Sci']))
    headr = list(itertools.product(['Exams', 'Labs'], ['I', 'II']))
@@ -1022,6 +1007,9 @@ You can use the same approach to read all files matching a pattern.  Here is an
 
 .. ipython:: python
 
+    import glob
+    import os
+
     files = glob.glob('file_*.csv')
     result = pd.concat([pd.read_csv(f) for f in files], ignore_index=True)
 
@@ -1081,6 +1069,8 @@ Option 1: pass rows explicitly to skip rows
 
 .. ipython:: python
 
+    from pandas.compat import StringIO
+
     pd.read_csv(StringIO(data), sep=';', skiprows=[11, 12],
                 index_col=0, parse_dates=True, header=10)
 
@@ -1327,6 +1317,8 @@ The :ref:`Timedeltas <timedeltas.timedeltas>` docs.
 
 .. ipython:: python
 
+   import datetime
+
    s = pd.Series(pd.date_range('2012-1-1', periods=3, freq='D'))
 
    s - s.max()
diff --git a/doc/source/dsintro.rst b/doc/source/dsintro.rst
index 968b30d7e9e2b..8bdb0005de53c 100644
--- a/doc/source/dsintro.rst
+++ b/doc/source/dsintro.rst
@@ -1,21 +1,7 @@
-.. currentmodule:: pandas
-
-.. ipython:: python
-   :suppress:
-
-   import numpy as np
-   np.set_printoptions(precision=4, suppress=True)
-   import pandas as pd
-   pd.set_option('display.precision', 4, 'display.max_columns', 8)
-   pd.options.display.max_rows = 15
-
-   import matplotlib
-   # matplotlib.style.use('default')
-   import matplotlib.pyplot as plt
-   plt.close('all')
-
 .. _dsintro:
 
+{{ header }}
+
 ************************
 Intro to Data Structures
 ************************
diff --git a/doc/source/enhancingperf.rst b/doc/source/enhancingperf.rst
index 1c873d604cfe0..c0546d653d532 100644
--- a/doc/source/enhancingperf.rst
+++ b/doc/source/enhancingperf.rst
@@ -1,19 +1,6 @@
 .. _enhancingperf:
 
-.. currentmodule:: pandas
-
-.. ipython:: python
-   :suppress:
-
-   import numpy as np
-   np.random.seed(123456)
-   np.set_printoptions(precision=4, suppress=True)
-   import pandas as pd
-   pd.options.display.max_rows=15
-
-   import os
-   import csv
-
+{{ header }}
 
 *********************
 Enhancing Performance
diff --git a/doc/source/gotchas.rst b/doc/source/gotchas.rst
index c62b836ed1f33..853e9e4bdf574 100644
--- a/doc/source/gotchas.rst
+++ b/doc/source/gotchas.rst
@@ -1,20 +1,11 @@
-.. currentmodule:: pandas
 .. _gotchas:
 
+{{ header }}
+
 ********************************
 Frequently Asked Questions (FAQ)
 ********************************
 
-.. ipython:: python
-   :suppress:
-
-   import numpy as np
-   import pandas as pd
-
-   np.random.seed(123456)
-   np.set_printoptions(precision=4, suppress=True)
-   pd.options.display.max_rows = 15
-
 .. _df-memory-usage:
 
 DataFrame memory usage
diff --git a/doc/source/groupby.rst b/doc/source/groupby.rst
index de188846cce76..76481b8cc765a 100644
--- a/doc/source/groupby.rst
+++ b/doc/source/groupby.rst
@@ -1,19 +1,6 @@
-.. currentmodule:: pandas
 .. _groupby:
 
-.. ipython:: python
-   :suppress:
-
-   import numpy as np
-   import matplotlib.pyplot as plt
-
-   import pandas as pd
-
-   plt.close('all')
-
-   np.random.seed(123456)
-   np.set_printoptions(precision=4, suppress=True)
-   pd.options.display.max_rows = 15
+{{ header }}
 
 *****************************
 Group By: split-apply-combine
diff --git a/doc/source/indexing.rst b/doc/source/indexing.rst
index 6ad9c573249a3..49289862a3acd 100644
--- a/doc/source/indexing.rst
+++ b/doc/source/indexing.rst
@@ -1,15 +1,6 @@
 .. _indexing:
 
-.. currentmodule:: pandas
-
-.. ipython:: python
-   :suppress:
-
-   import numpy as np
-   np.random.seed(123456)
-   np.set_printoptions(precision=4, suppress=True)
-   import pandas as pd
-   pd.options.display.max_rows=15
+{{ header }}
 
 ***************************
 Indexing and Selecting Data
diff --git a/doc/source/install.rst b/doc/source/install.rst
index 4a71dbcec17e6..b290b940c27fc 100644
--- a/doc/source/install.rst
+++ b/doc/source/install.rst
@@ -207,7 +207,7 @@ installed), make sure you have `pytest
 
 ::
 
-    >>> import pandas as pd
+    >>> import pandas as pd  # noqa: F811
     >>> pd.test()
     running: pytest --skip-slow --skip-network C:\Users\TP\Anaconda3\envs\py36\lib\site-packages\pandas
     ============================= test session starts =============================
diff --git a/doc/source/internals.rst b/doc/source/internals.rst
index c39dafa88db92..9c434928c214e 100644
--- a/doc/source/internals.rst
+++ b/doc/source/internals.rst
@@ -1,16 +1,6 @@
 .. _internals:
 
-.. currentmodule:: pandas
-
-.. ipython:: python
-   :suppress:
-
-   import numpy as np
-   import pandas as pd
-
-   np.random.seed(123456)
-   np.set_printoptions(precision=4, suppress=True)
-   pd.options.display.max_rows = 15
+{{ header }}
 
 *********
 Internals
diff --git a/doc/source/io.rst b/doc/source/io.rst
index 313c4d723d079..f1439e4a7a049 100644
--- a/doc/source/io.rst
+++ b/doc/source/io.rst
@@ -1,23 +1,10 @@
 .. _io:
 
-.. currentmodule:: pandas
+{{ header }}
 
 .. ipython:: python
    :suppress:
 
-   import csv
-   import os
-
-   import matplotlib.pyplot as plt
-   import numpy as np
-   import pandas as pd
-   from pandas.compat import StringIO, BytesIO
-
-
-   randn = np.random.randn
-   np.set_printoptions(precision=4, suppress=True)
-   plt.close('all')
-   pd.options.display.max_rows = 15
    clipdf = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': ['p', 'q', 'r']},
                          index=['x', 'y', 'z'])
 
@@ -144,6 +131,7 @@ usecols : list-like or callable, default ``None``
 
   .. ipython:: python
 
+     from pandas.compat import StringIO, BytesIO
      data = ('col1,col2,col3\n'
              'a,b,1\n'
              'a,b,2\n'
@@ -453,6 +441,8 @@ worth trying.
 .. ipython:: python
    :suppress:
 
+   import os
+   
    os.remove('foo.csv')
 
 .. _io.categorical:
@@ -1309,6 +1299,7 @@ We can get around this using ``dialect``:
 .. ipython:: python
    :okwarning:
 
+   import csv
    dia = csv.excel()
    dia.quoting = csv.QUOTE_NONE
    pd.read_csv(StringIO(data), dialect=dia)
diff --git a/doc/source/merging.rst b/doc/source/merging.rst
index 8a25d991c149b..af767d7687749 100644
--- a/doc/source/merging.rst
+++ b/doc/source/merging.rst
@@ -1,18 +1,10 @@
-.. currentmodule:: pandas
 .. _merging:
 
+{{ header }}
+
 .. ipython:: python
    :suppress:
 
-   import numpy as np
-   np.random.seed(123456)
-   import pandas as pd
-   pd.options.display.max_rows=15
-   randn = np.random.randn
-   np.set_printoptions(precision=4, suppress=True)
-
-   import matplotlib.pyplot as plt
-   plt.close('all')
    import pandas.util._doctools as doctools
    p = doctools.TablePlotter()
 
diff --git a/doc/source/missing_data.rst b/doc/source/missing_data.rst
index 7b6d338ee5b6a..ebe577feb706c 100644
--- a/doc/source/missing_data.rst
+++ b/doc/source/missing_data.rst
@@ -1,17 +1,7 @@
-.. currentmodule:: pandas
-
-.. ipython:: python
-   :suppress:
-
-   import numpy as np
-   import pandas as pd
-   pd.options.display.max_rows=15
-   import matplotlib
-   # matplotlib.style.use('default')
-   import matplotlib.pyplot as plt
-
 .. _missing_data:
 
+{{ header }}
+
 *************************
 Working with missing data
 *************************
diff --git a/doc/source/r_interface.rst b/doc/source/r_interface.rst
index f40f9199aaf66..4ec43a64cf98a 100644
--- a/doc/source/r_interface.rst
+++ b/doc/source/r_interface.rst
@@ -1,10 +1,6 @@
 .. _rpy:
 
-.. ipython:: python
-   :suppress:
-
-   import pandas as pd
-   pd.options.display.max_rows = 15
+{{ header }}
 
 
 ******************
diff --git a/doc/source/release.rst b/doc/source/release.rst
index af6fc23e12b78..67a30984ff0a7 100644
--- a/doc/source/release.rst
+++ b/doc/source/release.rst
@@ -1,18 +1,10 @@
 .. _release:
 
-.. currentmodule:: pandas
+{{ header }}
 
 .. ipython:: python
    :suppress:
 
-   import pandas as pd
-   import numpy as np
-   np.random.seed(123456)
-   np.set_printoptions(precision=4, suppress=True)
-   import matplotlib.pyplot as plt
-   plt.close('all')
-
-   pd.options.display.max_rows=15
    import pandas.util.testing as tm
 
 *************
diff --git a/doc/source/reshaping.rst b/doc/source/reshaping.rst
index 19857db1743e8..059e6eb2138f3 100644
--- a/doc/source/reshaping.rst
+++ b/doc/source/reshaping.rst
@@ -1,15 +1,6 @@
-.. currentmodule:: pandas
 .. _reshaping:
 
-.. ipython:: python
-   :suppress:
-
-   import numpy as np
-   import pandas as pd
-
-   np.random.seed(123456)
-   pd.options.display.max_rows = 15
-   np.set_printoptions(precision=4, suppress=True)
+{{ header }}
 
 **************************
 Reshaping and Pivot Tables
diff --git a/doc/source/sparse.rst b/doc/source/sparse.rst
index 5a4a211a5e6b4..9316dad762453 100644
--- a/doc/source/sparse.rst
+++ b/doc/source/sparse.rst
@@ -1,15 +1,6 @@
-.. currentmodule:: pandas
 .. _sparse:
 
-.. ipython:: python
-   :suppress:
-
-   import numpy as np
-   import pandas as pd
-
-   np.random.seed(123456)
-   np.set_printoptions(precision=4, suppress=True)
-   pd.options.display.max_rows = 15
+{{ header }}
 
 **********************
 Sparse data structures
diff --git a/doc/source/text.rst b/doc/source/text.rst
index d677cc38c9888..2361be765d889 100644
--- a/doc/source/text.rst
+++ b/doc/source/text.rst
@@ -1,14 +1,6 @@
-.. currentmodule:: pandas
 .. _text:
 
-.. ipython:: python
-   :suppress:
-
-   import numpy as np
-   import pandas as pd
-
-   np.set_printoptions(precision=4, suppress=True)
-   pd.options.display.max_rows = 15
+{{ header }}
 
 ======================
 Working with Text Data
diff --git a/doc/source/timedeltas.rst b/doc/source/timedeltas.rst
index 8dab39aafbf67..b32603cb78795 100644
--- a/doc/source/timedeltas.rst
+++ b/doc/source/timedeltas.rst
@@ -1,15 +1,6 @@
-.. currentmodule:: pandas
 .. _timedeltas:
 
-.. ipython:: python
-   :suppress:
-
-   import numpy as np
-   import pandas as pd
-
-   np.random.seed(123456)
-   np.set_printoptions(precision=4, suppress=True)
-   pd.options.display.max_rows = 15
+{{ header }}
 
 .. _timedeltas.timedeltas:
 
diff --git a/doc/source/timeseries.rst b/doc/source/timeseries.rst
index bca7b6a601dd2..0d6fc735f3025 100644
--- a/doc/source/timeseries.rst
+++ b/doc/source/timeseries.rst
@@ -1,15 +1,6 @@
-.. currentmodule:: pandas
 .. _timeseries:
 
-.. ipython:: python
-   :suppress:
-
-   import numpy as np
-   import pandas as pd
-
-   np.random.seed(123456)
-   np.set_printoptions(precision=4, suppress=True)
-   pd.options.display.max_rows = 15
+{{ header }}
 
 ********************************
 Time Series / Date functionality
diff --git a/doc/source/visualization.rst b/doc/source/visualization.rst
index 050d754d0ac8b..ce3c335b431ad 100644
--- a/doc/source/visualization.rst
+++ b/doc/source/visualization.rst
@@ -1,16 +1,6 @@
-.. currentmodule:: pandas
 .. _visualization:
 
-.. ipython:: python
-   :suppress:
-
-   import numpy as np
-   import pandas as pd
-
-   np.random.seed(123456)
-   np.set_printoptions(precision=4, suppress=True)
-   pd.options.display.max_rows = 15
-
+{{ header }}
 
 *************
 Visualization
@@ -21,6 +11,7 @@ We use the standard convention for referencing the matplotlib API:
 .. ipython:: python
 
    import matplotlib.pyplot as plt
+   plt.close('all')
 
 We provide the basics in pandas to easily create decent looking plots.
 See the :ref:`ecosystem <ecosystem.visualization>` section for visualization
diff --git a/doc/source/whatsnew/v0.10.0.rst b/doc/source/whatsnew/v0.10.0.rst
index 27f20111dbf96..9e45efca02eed 100644
--- a/doc/source/whatsnew/v0.10.0.rst
+++ b/doc/source/whatsnew/v0.10.0.rst
@@ -3,7 +3,13 @@
 v0.10.0 (December 17, 2012)
 ---------------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 This is a major release from 0.9.1 and includes many new features and
 enhancements along with a large number of bug fixes. There are also a number of
diff --git a/doc/source/whatsnew/v0.10.1.rst b/doc/source/whatsnew/v0.10.1.rst
index 5679babf07b73..33e8ddd52436d 100644
--- a/doc/source/whatsnew/v0.10.1.rst
+++ b/doc/source/whatsnew/v0.10.1.rst
@@ -3,7 +3,13 @@
 v0.10.1 (January 22, 2013)
 ---------------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 This is a minor release from 0.10.0 and includes new features, enhancements,
 and bug fixes. In particular, there is substantial new HDFStore functionality
diff --git a/doc/source/whatsnew/v0.11.0.rst b/doc/source/whatsnew/v0.11.0.rst
index 051d735e539aa..971caddcbd47f 100644
--- a/doc/source/whatsnew/v0.11.0.rst
+++ b/doc/source/whatsnew/v0.11.0.rst
@@ -3,7 +3,13 @@
 v0.11.0 (April 22, 2013)
 ------------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 This is a major release from 0.10.1 and includes many new features and
 enhancements along with a large number of bug fixes. The methods of Selecting
diff --git a/doc/source/whatsnew/v0.12.0.rst b/doc/source/whatsnew/v0.12.0.rst
index a462359b6e3c0..f2816915955cf 100644
--- a/doc/source/whatsnew/v0.12.0.rst
+++ b/doc/source/whatsnew/v0.12.0.rst
@@ -3,7 +3,13 @@
 v0.12.0 (July 24, 2013)
 ------------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 This is a major release from 0.11.0 and includes several new features and
 enhancements along with a large number of bug fixes.
diff --git a/doc/source/whatsnew/v0.13.0.rst b/doc/source/whatsnew/v0.13.0.rst
index 037347afb1d59..b11aed9284ab7 100644
--- a/doc/source/whatsnew/v0.13.0.rst
+++ b/doc/source/whatsnew/v0.13.0.rst
@@ -3,7 +3,13 @@
 v0.13.0 (January 3, 2014)
 ---------------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 This is a major release from 0.12.0 and includes a number of API changes, several new features and
 enhancements along with a large number of bug fixes.
diff --git a/doc/source/whatsnew/v0.13.1.rst b/doc/source/whatsnew/v0.13.1.rst
index 6a1b578cc08fb..63708e2565f4b 100644
--- a/doc/source/whatsnew/v0.13.1.rst
+++ b/doc/source/whatsnew/v0.13.1.rst
@@ -3,7 +3,13 @@
 v0.13.1 (February 3, 2014)
 --------------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 This is a minor release from 0.13.0 and includes a small number of API changes, several new features,
 enhancements, and performance improvements along with a large number of bug fixes. We recommend that all
diff --git a/doc/source/whatsnew/v0.14.0.rst b/doc/source/whatsnew/v0.14.0.rst
index 9606bbac2a1b3..6ef2a61228ad2 100644
--- a/doc/source/whatsnew/v0.14.0.rst
+++ b/doc/source/whatsnew/v0.14.0.rst
@@ -3,7 +3,13 @@
 v0.14.0 (May 31 , 2014)
 -----------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 This is a major release from 0.13.1 and includes a small number of API changes, several new features,
 enhancements, and performance improvements along with a large number of bug fixes. We recommend that all
diff --git a/doc/source/whatsnew/v0.14.1.rst b/doc/source/whatsnew/v0.14.1.rst
index 3b0ff5650d90d..3c2a5c60209db 100644
--- a/doc/source/whatsnew/v0.14.1.rst
+++ b/doc/source/whatsnew/v0.14.1.rst
@@ -3,7 +3,13 @@
 v0.14.1 (July 11, 2014)
 -----------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 This is a minor release from 0.14.0 and includes a small number of API changes, several new features,
 enhancements, and performance improvements along with a large number of bug fixes. We recommend that all
diff --git a/doc/source/whatsnew/v0.15.0.rst b/doc/source/whatsnew/v0.15.0.rst
index 00eda927a9c73..e7a7d8a7e3b06 100644
--- a/doc/source/whatsnew/v0.15.0.rst
+++ b/doc/source/whatsnew/v0.15.0.rst
@@ -3,7 +3,13 @@
 v0.15.0 (October 18, 2014)
 --------------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 This is a major release from 0.14.1 and includes a small number of API changes, several new features,
 enhancements, and performance improvements along with a large number of bug fixes. We recommend that all
diff --git a/doc/source/whatsnew/v0.15.1.rst b/doc/source/whatsnew/v0.15.1.rst
index 88127d4e1b8d8..be7cf04bcdd68 100644
--- a/doc/source/whatsnew/v0.15.1.rst
+++ b/doc/source/whatsnew/v0.15.1.rst
@@ -3,7 +3,13 @@
 v0.15.1 (November 9, 2014)
 --------------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 This is a minor bug-fix release from 0.15.0 and includes a small number of API changes, several new features,
 enhancements, and performance improvements along with a large number of bug fixes. We recommend that all
diff --git a/doc/source/whatsnew/v0.15.2.rst b/doc/source/whatsnew/v0.15.2.rst
index dd988cde88145..437dd3f8d3df6 100644
--- a/doc/source/whatsnew/v0.15.2.rst
+++ b/doc/source/whatsnew/v0.15.2.rst
@@ -3,7 +3,13 @@
 v0.15.2 (December 12, 2014)
 ---------------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 This is a minor release from 0.15.1 and includes a large number of bug fixes
 along with several new features, enhancements, and performance improvements.
diff --git a/doc/source/whatsnew/v0.16.0.rst b/doc/source/whatsnew/v0.16.0.rst
index d394b43a7ec88..8d2d589c44e1b 100644
--- a/doc/source/whatsnew/v0.16.0.rst
+++ b/doc/source/whatsnew/v0.16.0.rst
@@ -3,7 +3,13 @@
 v0.16.0 (March 22, 2015)
 ------------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 This is a major release from 0.15.2 and includes a small number of API changes, several new features,
 enhancements, and performance improvements along with a large number of bug fixes. We recommend that all
diff --git a/doc/source/whatsnew/v0.16.1.rst b/doc/source/whatsnew/v0.16.1.rst
index aae96a5d63c14..5d98d3715a933 100644
--- a/doc/source/whatsnew/v0.16.1.rst
+++ b/doc/source/whatsnew/v0.16.1.rst
@@ -3,7 +3,13 @@
 v0.16.1 (May 11, 2015)
 ----------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 This is a minor bug-fix release from 0.16.0 and includes a a large number of
 bug fixes along several new features, enhancements, and performance improvements.
diff --git a/doc/source/whatsnew/v0.16.2.rst b/doc/source/whatsnew/v0.16.2.rst
index acae3a55d5f78..932f70d3e0e19 100644
--- a/doc/source/whatsnew/v0.16.2.rst
+++ b/doc/source/whatsnew/v0.16.2.rst
@@ -3,7 +3,13 @@
 v0.16.2 (June 12, 2015)
 -----------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 This is a minor bug-fix release from 0.16.1 and includes a a large number of
 bug fixes along some new features (:meth:`~DataFrame.pipe` method), enhancements, and performance improvements.
diff --git a/doc/source/whatsnew/v0.17.0.rst b/doc/source/whatsnew/v0.17.0.rst
index abde8d953f4df..51b86899e1bc5 100644
--- a/doc/source/whatsnew/v0.17.0.rst
+++ b/doc/source/whatsnew/v0.17.0.rst
@@ -3,7 +3,13 @@
 v0.17.0 (October 9, 2015)
 -------------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 This is a major release from 0.16.2 and includes a small number of API changes, several new features,
 enhancements, and performance improvements along with a large number of bug fixes. We recommend that all
diff --git a/doc/source/whatsnew/v0.17.1.rst b/doc/source/whatsnew/v0.17.1.rst
index 44554a88fba04..77dda4cfb1f44 100644
--- a/doc/source/whatsnew/v0.17.1.rst
+++ b/doc/source/whatsnew/v0.17.1.rst
@@ -3,7 +3,13 @@
 v0.17.1 (November 21, 2015)
 ---------------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 .. note::
 
diff --git a/doc/source/whatsnew/v0.18.0.rst b/doc/source/whatsnew/v0.18.0.rst
index 5cd4163b1a7a5..da7d409fb8922 100644
--- a/doc/source/whatsnew/v0.18.0.rst
+++ b/doc/source/whatsnew/v0.18.0.rst
@@ -3,7 +3,13 @@
 v0.18.0 (March 13, 2016)
 ------------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 This is a major release from 0.17.1 and includes a small number of API changes, several new features,
 enhancements, and performance improvements along with a large number of bug fixes. We recommend that all
diff --git a/doc/source/whatsnew/v0.18.1.rst b/doc/source/whatsnew/v0.18.1.rst
index 1dc01d7f1f745..65f0285ad32c9 100644
--- a/doc/source/whatsnew/v0.18.1.rst
+++ b/doc/source/whatsnew/v0.18.1.rst
@@ -3,7 +3,13 @@
 v0.18.1 (May 3, 2016)
 ---------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 This is a minor bug-fix release from 0.18.0 and includes a large number of
 bug fixes along with several new features, enhancements, and performance improvements.
diff --git a/doc/source/whatsnew/v0.19.0.rst b/doc/source/whatsnew/v0.19.0.rst
index 467319a4527d1..1e4e7a6c80fa4 100644
--- a/doc/source/whatsnew/v0.19.0.rst
+++ b/doc/source/whatsnew/v0.19.0.rst
@@ -3,7 +3,13 @@
 v0.19.0 (October 2, 2016)
 -------------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 This is a major release from 0.18.1 and includes number of API changes, several new features,
 enhancements, and performance improvements along with a large number of bug fixes. We recommend that all
diff --git a/doc/source/whatsnew/v0.19.1.rst b/doc/source/whatsnew/v0.19.1.rst
index 0c909fa4195d7..12f3e985565e0 100644
--- a/doc/source/whatsnew/v0.19.1.rst
+++ b/doc/source/whatsnew/v0.19.1.rst
@@ -3,7 +3,13 @@
 v0.19.1 (November 3, 2016)
 --------------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 This is a minor bug-fix release from 0.19.0 and includes some small regression fixes,
 bug fixes and performance improvements.
diff --git a/doc/source/whatsnew/v0.19.2.rst b/doc/source/whatsnew/v0.19.2.rst
index 1cded6d2c94e2..14310ceb45b4a 100644
--- a/doc/source/whatsnew/v0.19.2.rst
+++ b/doc/source/whatsnew/v0.19.2.rst
@@ -3,7 +3,13 @@
 v0.19.2 (December 24, 2016)
 ---------------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 This is a minor bug-fix release in the 0.19.x series and includes some small regression fixes,
 bug fixes and performance improvements.
diff --git a/doc/source/whatsnew/v0.20.0.rst b/doc/source/whatsnew/v0.20.0.rst
index 8456449ee4419..ef422f991464f 100644
--- a/doc/source/whatsnew/v0.20.0.rst
+++ b/doc/source/whatsnew/v0.20.0.rst
@@ -3,7 +3,13 @@
 v0.20.1 (May 5, 2017)
 ---------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 This is a major release from 0.19.2 and includes a number of API changes, deprecations, new features,
 enhancements, and performance improvements along with a large number of bug fixes. We recommend that all
diff --git a/doc/source/whatsnew/v0.20.2.rst b/doc/source/whatsnew/v0.20.2.rst
index 784cd09edff30..b2592579eb03f 100644
--- a/doc/source/whatsnew/v0.20.2.rst
+++ b/doc/source/whatsnew/v0.20.2.rst
@@ -3,7 +3,13 @@
 v0.20.2 (June 4, 2017)
 ----------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 This is a minor bug-fix release in the 0.20.x series and includes some small regression fixes,
 bug fixes and performance improvements.
diff --git a/doc/source/whatsnew/v0.20.3.rst b/doc/source/whatsnew/v0.20.3.rst
index 47bfcc761b088..99f7ff2e36d25 100644
--- a/doc/source/whatsnew/v0.20.3.rst
+++ b/doc/source/whatsnew/v0.20.3.rst
@@ -3,7 +3,13 @@
 v0.20.3 (July 7, 2017)
 -----------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 This is a minor bug-fix release in the 0.20.x series and includes some small regression fixes
 and bug fixes. We recommend that all users upgrade to this version.
diff --git a/doc/source/whatsnew/v0.21.0.rst b/doc/source/whatsnew/v0.21.0.rst
index c9a90f3ada7e5..73bdedb3d3194 100644
--- a/doc/source/whatsnew/v0.21.0.rst
+++ b/doc/source/whatsnew/v0.21.0.rst
@@ -3,7 +3,13 @@
 v0.21.0 (October 27, 2017)
 --------------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 This is a major release from 0.20.3 and includes a number of API changes, deprecations, new features,
 enhancements, and performance improvements along with a large number of bug fixes. We recommend that all
diff --git a/doc/source/whatsnew/v0.21.1.rst b/doc/source/whatsnew/v0.21.1.rst
index bf13d5d67ed63..c8897ca86e8cf 100644
--- a/doc/source/whatsnew/v0.21.1.rst
+++ b/doc/source/whatsnew/v0.21.1.rst
@@ -3,7 +3,13 @@
 v0.21.1 (December 12, 2017)
 ---------------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 This is a minor bug-fix release in the 0.21.x series and includes some small regression fixes,
 bug fixes and performance improvements.
diff --git a/doc/source/whatsnew/v0.22.0.rst b/doc/source/whatsnew/v0.22.0.rst
index f05b84a9d8902..1fb87c9f5433f 100644
--- a/doc/source/whatsnew/v0.22.0.rst
+++ b/doc/source/whatsnew/v0.22.0.rst
@@ -3,7 +3,13 @@
 v0.22.0 (December 29, 2017)
 ---------------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 This is a major release from 0.21.1 and includes a single, API-breaking change.
 We recommend that all users upgrade to this version after carefully reading the
diff --git a/doc/source/whatsnew/v0.23.0.rst b/doc/source/whatsnew/v0.23.0.rst
index f84517a3e3b9c..d8eb337fd27d2 100644
--- a/doc/source/whatsnew/v0.23.0.rst
+++ b/doc/source/whatsnew/v0.23.0.rst
@@ -3,7 +3,13 @@
 What's new in 0.23.0 (May 15, 2018)
 -----------------------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 This is a major release from 0.22.0 and includes a number of API changes,
 deprecations, new features, enhancements, and performance improvements along
diff --git a/doc/source/whatsnew/v0.23.1.rst b/doc/source/whatsnew/v0.23.1.rst
index e8e0060c48337..f8bfced171a7c 100644
--- a/doc/source/whatsnew/v0.23.1.rst
+++ b/doc/source/whatsnew/v0.23.1.rst
@@ -3,7 +3,13 @@
 What's New in 0.23.1 (June 12, 2018)
 ------------------------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 This is a minor bug-fix release in the 0.23.x series and includes some small regression fixes
 and bug fixes. We recommend that all users upgrade to this version.
diff --git a/doc/source/whatsnew/v0.23.2.rst b/doc/source/whatsnew/v0.23.2.rst
index 573a30f17846b..9523724827722 100644
--- a/doc/source/whatsnew/v0.23.2.rst
+++ b/doc/source/whatsnew/v0.23.2.rst
@@ -3,7 +3,13 @@
 What's New in 0.23.2 (July 5, 2018)
 -----------------------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 This is a minor bug-fix release in the 0.23.x series and includes some small regression fixes
 and bug fixes. We recommend that all users upgrade to this version.
diff --git a/doc/source/whatsnew/v0.23.3.rst b/doc/source/whatsnew/v0.23.3.rst
index 29758e54b437b..3b1a0cfa5f273 100644
--- a/doc/source/whatsnew/v0.23.3.rst
+++ b/doc/source/whatsnew/v0.23.3.rst
@@ -3,7 +3,7 @@
 What's New in 0.23.3 (July 7, 2018)
 -----------------------------------
 
-{{ common_imports }}
+{{ header }}
 
 This release fixes a build issue with the sdist for Python 3.7 (:issue:`21785`)
 There are no other changes.
diff --git a/doc/source/whatsnew/v0.23.4.rst b/doc/source/whatsnew/v0.23.4.rst
index c8f08d0bb7091..75fb18a648d0a 100644
--- a/doc/source/whatsnew/v0.23.4.rst
+++ b/doc/source/whatsnew/v0.23.4.rst
@@ -3,7 +3,13 @@
 What's New in 0.23.4 (August 3, 2018)
 -------------------------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 This is a minor bug-fix release in the 0.23.x series and includes some small regression fixes
 and bug fixes. We recommend that all users upgrade to this version.
diff --git a/doc/source/whatsnew/v0.24.0.rst b/doc/source/whatsnew/v0.24.0.rst
index 53ae3200d2adb..a91c62250ef9d 100644
--- a/doc/source/whatsnew/v0.24.0.rst
+++ b/doc/source/whatsnew/v0.24.0.rst
@@ -8,7 +8,13 @@ What's New in 0.24.0 (Month XX, 2018)
    Starting January 1, 2019, pandas feature releases will support Python 3 only.
    See :ref:`install.dropping-27` for more.
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 These are the changes in pandas 0.24.0. See :ref:`release` for a full changelog
 including other versions of pandas.
diff --git a/doc/source/whatsnew/v0.4.x.rst b/doc/source/whatsnew/v0.4.x.rst
index e54614849c93b..ebf5286a41b6e 100644
--- a/doc/source/whatsnew/v0.4.x.rst
+++ b/doc/source/whatsnew/v0.4.x.rst
@@ -3,7 +3,7 @@
 v.0.4.3 through v0.4.1 (September 25 - October 9, 2011)
 -------------------------------------------------------
 
-{{ common_imports }}
+{{ header }}
 
 New Features
 ~~~~~~~~~~~~
diff --git a/doc/source/whatsnew/v0.5.0.rst b/doc/source/whatsnew/v0.5.0.rst
index c6d17cb1e1290..4e635a5fe6859 100644
--- a/doc/source/whatsnew/v0.5.0.rst
+++ b/doc/source/whatsnew/v0.5.0.rst
@@ -4,7 +4,13 @@
 v.0.5.0 (October 24, 2011)
 --------------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 New Features
 ~~~~~~~~~~~~
diff --git a/doc/source/whatsnew/v0.6.0.rst b/doc/source/whatsnew/v0.6.0.rst
index de45b3b383129..ba2c6aec40f50 100644
--- a/doc/source/whatsnew/v0.6.0.rst
+++ b/doc/source/whatsnew/v0.6.0.rst
@@ -3,7 +3,13 @@
 v.0.6.0 (November 25, 2011)
 ---------------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 New Features
 ~~~~~~~~~~~~
diff --git a/doc/source/whatsnew/v0.7.0.rst b/doc/source/whatsnew/v0.7.0.rst
index e278bc0738108..7049e836e2034 100644
--- a/doc/source/whatsnew/v0.7.0.rst
+++ b/doc/source/whatsnew/v0.7.0.rst
@@ -3,7 +3,13 @@
 v.0.7.0 (February 9, 2012)
 --------------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 New features
 ~~~~~~~~~~~~
diff --git a/doc/source/whatsnew/v0.7.1.rst b/doc/source/whatsnew/v0.7.1.rst
index f1a133797fd59..db14c5af71923 100644
--- a/doc/source/whatsnew/v0.7.1.rst
+++ b/doc/source/whatsnew/v0.7.1.rst
@@ -3,7 +3,13 @@
 v.0.7.1 (February 29, 2012)
 ---------------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 This release includes a few new features and addresses over a dozen bugs in
 0.7.0.
diff --git a/doc/source/whatsnew/v0.7.2.rst b/doc/source/whatsnew/v0.7.2.rst
index b870db956f4f1..4898a209fb33b 100644
--- a/doc/source/whatsnew/v0.7.2.rst
+++ b/doc/source/whatsnew/v0.7.2.rst
@@ -3,7 +3,13 @@
 v.0.7.2 (March 16, 2012)
 ---------------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 This release targets bugs in 0.7.1, and adds a few minor features.
 
diff --git a/doc/source/whatsnew/v0.7.3.rst b/doc/source/whatsnew/v0.7.3.rst
index 30e22f105656c..6f7927499db78 100644
--- a/doc/source/whatsnew/v0.7.3.rst
+++ b/doc/source/whatsnew/v0.7.3.rst
@@ -3,7 +3,13 @@
 v.0.7.3 (April 12, 2012)
 ------------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 This is a minor release from 0.7.2 and fixes many minor bugs and adds a number
 of nice new features. There are also a couple of API changes to note; these
diff --git a/doc/source/whatsnew/v0.8.0.rst b/doc/source/whatsnew/v0.8.0.rst
index eedaaa3dfa8bd..3457774f98811 100644
--- a/doc/source/whatsnew/v0.8.0.rst
+++ b/doc/source/whatsnew/v0.8.0.rst
@@ -3,7 +3,13 @@
 v0.8.0 (June 29, 2012)
 ------------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 This is a major release from 0.7.3 and includes extensive work on the time
 series handling and processing infrastructure as well as a great deal of new
diff --git a/doc/source/whatsnew/v0.8.1.rst b/doc/source/whatsnew/v0.8.1.rst
index 468b99341163c..20338cf79215c 100644
--- a/doc/source/whatsnew/v0.8.1.rst
+++ b/doc/source/whatsnew/v0.8.1.rst
@@ -3,7 +3,13 @@
 v0.8.1 (July 22, 2012)
 ----------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 This release includes a few new features, performance enhancements, and over 30
 bug fixes from 0.8.0.  New features include notably NA friendly string
diff --git a/doc/source/whatsnew/v0.9.0.rst b/doc/source/whatsnew/v0.9.0.rst
index ee4e8c338c984..eebc044255bbc 100644
--- a/doc/source/whatsnew/v0.9.0.rst
+++ b/doc/source/whatsnew/v0.9.0.rst
@@ -1,6 +1,12 @@
 .. _whatsnew_0900:
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 v0.9.0 (October 7, 2012)
 ------------------------
diff --git a/doc/source/whatsnew/v0.9.1.rst b/doc/source/whatsnew/v0.9.1.rst
index fe3de9be95a74..6620f644cf527 100644
--- a/doc/source/whatsnew/v0.9.1.rst
+++ b/doc/source/whatsnew/v0.9.1.rst
@@ -3,7 +3,13 @@
 v0.9.1 (November 14, 2012)
 --------------------------
 
-{{ common_imports }}
+{{ header }}
+
+.. ipython:: python
+   :suppress:
+
+   from pandas import * # noqa F401, F403
+
 
 This is a bug fix release from 0.9.0 and includes several new features and
 enhancements along with a large number of bug fixes. The new features include
diff --git a/setup.cfg b/setup.cfg
index 44df79d1b60d2..defecfbb158de 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -31,6 +31,9 @@ exclude =
     env  # exclude asv benchmark environments from linting
 
 [flake8-rst]
+bootstrap =
+    import pandas as pd
+    import numpy as np
 ignore = E402,  # module level import not at top of file
          W503,  # line break before binary operator
 exclude =
diff --git a/tmp.xlsx b/tmp.xlsx
new file mode 100644
index 0000000000000..199e9049bfa96
Binary files /dev/null and b/tmp.xlsx differ


Code review comments:
diff_hunk: @@ -14,8 +14,8 @@ As is customary, we import pandas and NumPy as follows:
 
 .. ipython:: python
 
-    import pandas as pd
-    import numpy as np
+    import pandas as pd    # noqa: F811
+    import numpy as np     # noqa: F811
path: doc/source/comparison_with_sas.rst
text: @user1:
why don't we use the header here? you can add the `F811` to the `--bootstrap` parameter value if needed

@author:
This is a tutorial of sorts and the tutorial walks thru the process of importing pandas and numpy visibly (not with a :supress: ). I think without the visible import of pandas the tutorial will not make sense. 

@user1:
Makes sense. But can you still include the header in those files? Besides the imports, there is other stuff. And we will potentially add more, and expect to be applied to 100% of rst files. Thanks!

diff_hunk: @@ -814,9 +816,8 @@ We would name this file ``test_cool_feature.py`` and put in an appropriate place
 .. code-block:: python
 
    import pytest
-   import numpy as np
-   import pandas as pd
-   from pandas.util import testing as tm
+   import numpy as np        # noqa: F811
+   import pandas as pd       # noqa: F811
path: doc/source/contributing.rst
text: @user1:
same

@author:
This similar to the issue above. The tutorial presents a complete block of code to be copied and saved as a .py file. Without the explicit import, anyone following the tutorial will not be able to replicate the results. It might make sense to include this block as a non executable block.

diff_hunk: @@ -207,7 +207,7 @@ installed), make sure you have `pytest
 
 ::
 
-    >>> import pandas as pd
+    >>> import pandas as pd  # noqa: F811
path: doc/source/install.rst
text: @user1:
same

@author:
On this I agree with you. I can remove the explicit import.