Skip to content

Commit ee7307c

Browse files
Update guide (#73)
* add doctest tips * small correctins * add note on possibly needing to recompile pandas * rebuild
1 parent 00951e1 commit ee7307c

18 files changed

+391
-339
lines changed

pandas/guide/_sources/pandas_docstring.rst.txt

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ Next example gives an idea on how a docstring looks like:
2020
.. code-block:: python
2121
2222
def add(num1, num2):
23-
"""Add up two integer numbers.
23+
"""
24+
Add up two integer numbers.
2425
2526
This function simply wraps the `+` operator, and does not
2627
do anything interesting, except for illustrating what is
@@ -265,7 +266,7 @@ argument means, which can be added after a comma "int, default -1, meaning all
265266
cpus".
266267

267268
In cases where the default value is `None`, meaning that the value will not be
268-
used. Instead of "str, default None" is preferred "str, optional".
269+
used. Instead of "str, default None", it is preferred to write "str, optional".
269270
When `None` is a value being used, we will keep the form "str, default None".
270271
For example, in `df.to_csv(compression=None)`, `None` is not a value being used,
271272
but means that compression is optional, and no compression is being used if not
@@ -535,7 +536,8 @@ For example:
535536
536537
class Series:
537538
def head(self):
538-
"""Return the first 5 elements of the Series.
539+
"""
540+
Return the first 5 elements of the Series.
539541
540542
This function is mainly useful to preview the values of the
541543
Series without displaying the whole of it.
@@ -603,7 +605,8 @@ A simple example could be:
603605
604606
class Series:
605607
def head(self, n=5):
606-
"""Return the first elements of the Series.
608+
"""
609+
Return the first elements of the Series.
607610
608611
This function is mainly useful to preview the values of the
609612
Series without displaying the whole of it.
@@ -815,6 +818,52 @@ positional arguments `head(3)`.
815818
pass
816819
817820
821+
.. _docstring.doctest_tips:
822+
823+
Tips for getting your examples pass the doctests
824+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
825+
826+
Getting the examples pass the doctests in the validation script can sometimes
827+
be tricky. Here are some attention points:
828+
829+
* Import all needed libraries (except for pandas and numpy, those are already
830+
imported as `import pandas as pd` and `import numpy as np`) and define all
831+
variables you use in the example.
832+
833+
* Try to avoid using random data.
834+
835+
* If you have a code snippet that wraps multiple lines, you need to use '...'
836+
on the continued lines:
837+
838+
::
839+
840+
>>> df = pd.DataFrame([[1, 2, 3], [4, 5, 6]], index=['a', 'b', 'c'],
841+
... columns=['A', 'B'])
842+
843+
* If you want to show a case where an exception is raised, you can do::
844+
845+
>>> pd.to_datetime(["712-01-01"])
846+
Traceback (most recent call last):
847+
OutOfBoundsDatetime: Out of bounds nanosecond timestamp: 712-01-01 00:00:00
848+
849+
It is essential to include the "Traceback (most recent call last):", but for
850+
the actual error only the error name is sufficient.
851+
852+
* If there is a small part of the result that can vary (e.g. a hash in an object
853+
represenation), you can use ``...`` to represent this part.
854+
855+
If you want to show that ``s.plot()`` returns a matplotlib AxesSubplot object,
856+
this will fail the doctest::
857+
858+
>>> s.plot()
859+
<matplotlib.axes._subplots.AxesSubplot at 0x7efd0c0b0690>
860+
861+
However, you can do (notice the comment that needs to be added)::
862+
863+
>>> s.plot() # doctest: +ELLIPSIS
864+
<matplotlib.axes._subplots.AxesSubplot at ...>
865+
866+
818867
.. _docstring.example_plots:
819868

820869
Plots in examples
@@ -839,7 +888,7 @@ plot will be generated automatically when building the documentation.
839888
.. plot::
840889
:context: close-figs
841890
842-
>>> s = pd.Series([1, 2, 3])
843-
>>> s.plot()
891+
>>> s = pd.Series([1, 2, 3])
892+
>>> s.plot()
844893
"""
845894
pass

pandas/guide/_sources/pandas_pr.rst.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ technical parts of the pandas docstring convention. To run the script,
1616
execute in your terminal:
1717

1818
| ``cd <pandas-dir>``
19-
| ``scripts/validate_docstrings.py <your-function-or-method>``
19+
| ``python scripts/validate_docstrings.py <your-function-or-method>``
2020
2121
where `<your-function-or-method>` is for example `pandas.DataFrame.head`,
2222
`pandas.Series.tail` or `pandas.to_datetime`.
@@ -34,6 +34,15 @@ Finally, the output will also contain errors from running the examples.
3434

3535
With few exceptions, you should fix all the errors before continuing.
3636

37+
If you are changing a docstring in a cython file (with ``.pyx`` extension),
38+
you need to rebuild the pandas C extensions to be able to see the resulting
39+
changes in the docstring and to validate the docstring with the command
40+
above.
41+
To recompile pandas, run:
42+
43+
| ``cd <pandas-dir>``
44+
| ``python setup.py build_ext --inplace``
45+
3746
2. Visual validation of the docstring
3847
-------------------------------------
3948

@@ -114,6 +123,9 @@ style by running the command:
114123

115124
| ``git diff upstream/master -u -- "*.py" | flake8 --diff``
116125
126+
If you don't already have flake8 installed, you can install it in the Anaconda Prompt it via
127+
| ``conda install flake8``
128+
117129
If the command does not return any warning, mark that checkbox with an X (do
118130
not leave spaces inside the brackets, use `[X]`). If it returns a warning,
119131
fix it, commit your changes, and push to your remote branch before opening

pandas/guide/_static/alabaster.css

Lines changed: 27 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -15,49 +15,14 @@
1515

1616

1717

18-
19-
20-
21-
22-
23-
24-
25-
26-
27-
28-
29-
30-
31-
32-
33-
34-
35-
36-
37-
38-
39-
40-
41-
42-
43-
44-
45-
46-
47-
48-
49-
50-
51-
52-
5318
@import url("basic.css");
5419

5520
/* -- page layout ----------------------------------------------------------- */
5621

5722
body {
5823
font-family: 'goudy old style', 'minion pro', 'bell mt', Georgia, 'Hiragino Mincho Pro', serif;
5924
font-size: 17px;
60-
background-color: #fff;
25+
background-color: white;
6126
color: #000;
6227
margin: 0;
6328
padding: 0;
@@ -89,7 +54,7 @@ hr {
8954
}
9055

9156
div.body {
92-
background-color: #fff;
57+
background-color: #ffffff;
9358
color: #3E4349;
9459
padding: 0 30px 0 30px;
9560
}
@@ -111,7 +76,7 @@ div.footer a {
11176
}
11277

11378
p.caption {
114-
font-family: inherit;
79+
font-family: ;
11580
font-size: inherit;
11681
}
11782

@@ -267,15 +232,19 @@ div.body p, div.body dd, div.body li {
267232
div.admonition {
268233
margin: 20px 0px;
269234
padding: 10px 30px;
270-
background-color: #EEE;
271-
border: 1px solid #CCC;
235+
background-color: #FCC;
236+
border: 1px solid #FAA;
272237
}
273238

274-
div.admonition tt.xref, div.admonition code.xref, div.admonition a tt {
275-
background-color: #FBFBFB;
239+
div.admonition tt.xref, div.admonition a tt {
276240
border-bottom: 1px solid #fafafa;
277241
}
278242

243+
dd div.admonition {
244+
margin-left: -60px;
245+
padding-left: 60px;
246+
}
247+
279248
div.admonition p.admonition-title {
280249
font-family: 'Garamond', 'Georgia', serif;
281250
font-weight: normal;
@@ -290,71 +259,25 @@ div.admonition p.last {
290259
}
291260

292261
div.highlight {
293-
background-color: #fff;
262+
background-color: white;
294263
}
295264

296265
dt:target, .highlight {
297266
background: #FAF3E8;
298267
}
299268

300-
div.warning {
301-
background-color: #FCC;
302-
border: 1px solid #FAA;
303-
}
304-
305-
div.danger {
306-
background-color: #FCC;
307-
border: 1px solid #FAA;
308-
-moz-box-shadow: 2px 2px 4px #D52C2C;
309-
-webkit-box-shadow: 2px 2px 4px #D52C2C;
310-
box-shadow: 2px 2px 4px #D52C2C;
311-
}
312-
313-
div.error {
314-
background-color: #FCC;
315-
border: 1px solid #FAA;
316-
-moz-box-shadow: 2px 2px 4px #D52C2C;
317-
-webkit-box-shadow: 2px 2px 4px #D52C2C;
318-
box-shadow: 2px 2px 4px #D52C2C;
319-
}
320-
321-
div.caution {
322-
background-color: #FCC;
323-
border: 1px solid #FAA;
324-
}
325-
326-
div.attention {
327-
background-color: #FCC;
328-
border: 1px solid #FAA;
329-
}
330-
331-
div.important {
332-
background-color: #EEE;
333-
border: 1px solid #CCC;
334-
}
335-
336269
div.note {
337270
background-color: #EEE;
338271
border: 1px solid #CCC;
339272
}
340273

341-
div.tip {
342-
background-color: #EEE;
343-
border: 1px solid #CCC;
344-
}
345-
346-
div.hint {
347-
background-color: #EEE;
348-
border: 1px solid #CCC;
349-
}
350-
351274
div.seealso {
352275
background-color: #EEE;
353276
border: 1px solid #CCC;
354277
}
355278

356279
div.topic {
357-
background-color: #EEE;
280+
background-color: #eee;
358281
}
359282

360283
p.admonition-title {
@@ -389,16 +312,16 @@ tt.descname, code.descname {
389312
}
390313

391314
img.screenshot {
392-
-moz-box-shadow: 2px 2px 4px #EEE;
393-
-webkit-box-shadow: 2px 2px 4px #EEE;
394-
box-shadow: 2px 2px 4px #EEE;
315+
-moz-box-shadow: 2px 2px 4px #eee;
316+
-webkit-box-shadow: 2px 2px 4px #eee;
317+
box-shadow: 2px 2px 4px #eee;
395318
}
396319

397320
table.docutils {
398321
border: 1px solid #888;
399-
-moz-box-shadow: 2px 2px 4px #EEE;
400-
-webkit-box-shadow: 2px 2px 4px #EEE;
401-
box-shadow: 2px 2px 4px #EEE;
322+
-moz-box-shadow: 2px 2px 4px #eee;
323+
-webkit-box-shadow: 2px 2px 4px #eee;
324+
box-shadow: 2px 2px 4px #eee;
402325
}
403326

404327
table.docutils td, table.docutils th {
@@ -438,16 +361,6 @@ table.field-list p {
438361
margin-bottom: 0.8em;
439362
}
440363

441-
/* Cloned from
442-
* https://github.com/sphinx-doc/sphinx/commit/ef60dbfce09286b20b7385333d63a60321784e68
443-
*/
444-
.field-name {
445-
-moz-hyphens: manual;
446-
-ms-hyphens: manual;
447-
-webkit-hyphens: manual;
448-
hyphens: manual;
449-
}
450-
451364
table.footnote td.label {
452365
width: .1px;
453366
padding: 0.3em 0 0.3em 0.5em;
@@ -484,15 +397,16 @@ pre {
484397
line-height: 1.3em;
485398
}
486399

487-
div.viewcode-block:target {
488-
background: #ffd;
489-
}
490-
491400
dl pre, blockquote pre, li pre {
492401
margin-left: 0;
493402
padding-left: 30px;
494403
}
495404

405+
dl dl pre {
406+
margin-left: -90px;
407+
padding-left: 90px;
408+
}
409+
496410
tt, code {
497411
background-color: #ecf0f3;
498412
color: #222;
@@ -501,7 +415,7 @@ tt, code {
501415

502416
tt.xref, code.xref, a tt {
503417
background-color: #FBFBFB;
504-
border-bottom: 1px solid #fff;
418+
border-bottom: 1px solid white;
505419
}
506420

507421
a.reference {
@@ -603,7 +517,7 @@ a:hover tt, a:hover code {
603517

604518
div.documentwrapper {
605519
float: none;
606-
background: #fff;
520+
background: white;
607521
}
608522

609523
div.sphinxsidebar {
@@ -618,7 +532,7 @@ a:hover tt, a:hover code {
618532

619533
div.sphinxsidebar h3, div.sphinxsidebar h4, div.sphinxsidebar p,
620534
div.sphinxsidebar h3 a {
621-
color: #fff;
535+
color: white;
622536
}
623537

624538
div.sphinxsidebar a {

0 commit comments

Comments
 (0)