Skip to content

DOC: Use a standard header for all rst files #24086

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 9, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 2 additions & 19 deletions doc/source/10min.rst
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -773,6 +755,7 @@ CSV
.. ipython:: python
:suppress:

import os
os.remove('foo.csv')

HDF5
Expand Down
11 changes: 1 addition & 10 deletions doc/source/advanced.rst
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 2 additions & 11 deletions doc/source/basics.rst
Original file line number Diff line number Diff line change
@@ -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
==============================
Expand Down
12 changes: 1 addition & 11 deletions doc/source/categorical.rst
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 1 addition & 7 deletions doc/source/comparison_with_r.rst
Original file line number Diff line number Diff line change
@@ -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
*******************************
Expand Down
4 changes: 2 additions & 2 deletions doc/source/comparison_with_sas.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why don't we use the header here? you can add the F811 to the --bootstrap parameter value if needed

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!



.. note::
Expand Down
18 changes: 2 additions & 16 deletions doc/source/computation.rst
Original file line number Diff line number Diff line change
@@ -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
===================

Expand Down
10 changes: 5 additions & 5 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 7 additions & 4 deletions doc/source/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ Otherwise, you need to do it manually:

import warnings


def old_func():
"""Summary of the function.

Expand All @@ -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

Expand Down Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.



@pytest.mark.parametrize('dtype', ['int8', 'int16', 'int32', 'int64'])
Expand Down Expand Up @@ -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()

Expand Down
32 changes: 12 additions & 20 deletions doc/source/cookbook.rst
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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']))
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -1081,6 +1069,8 @@ Option 1: pass rows explicitly to skip rows

.. ipython:: python

from pandas.compat import StringIO
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side note: in the public docs I think we should use the standard python from io import StringIO (as I don't think we should recommend people normal users to use pandas.compat)


pd.read_csv(StringIO(data), sep=';', skiprows=[11, 12],
index_col=0, parse_dates=True, header=10)

Expand Down Expand Up @@ -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()
Expand Down
18 changes: 2 additions & 16 deletions doc/source/dsintro.rst
Original file line number Diff line number Diff line change
@@ -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
************************
Expand Down
15 changes: 1 addition & 14 deletions doc/source/enhancingperf.rst
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 2 additions & 11 deletions doc/source/gotchas.rst
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 1 addition & 14 deletions doc/source/groupby.rst
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 1 addition & 10 deletions doc/source/indexing.rst
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion doc/source/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ installed), make sure you have `pytest

::

>>> import pandas as pd
>>> import pandas as pd # noqa: F811
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

>>> pd.test()
running: pytest --skip-slow --skip-network C:\Users\TP\Anaconda3\envs\py36\lib\site-packages\pandas
============================= test session starts =============================
Expand Down
Loading