@@ -101,7 +101,8 @@ docstrings, but is it common to have inline code, which is presented between
101
101
backticks. It is considered inline code:
102
102
103
103
- The name of a parameter
104
- - Python code, a module, function, built-in, type, literal... (e.g. `os `, `list `, `numpy.abs `, `datetime.date `, `True `)
104
+ - Python code, a module, function, built-in, type, literal... (e.g. ``os ``,
105
+ ``list ``, ``numpy.abs ``, ``datetime.date ``, ``True ``)
105
106
- A pandas class (in the form ``:class:`~pandas.Series` ``)
106
107
- A pandas method (in the form ``:meth:`pandas.Series.sum` ``)
107
108
- A pandas function (in the form ``:func:`pandas.to_datetime` ``)
@@ -149,8 +150,8 @@ backticks. It is considered inline code:
149
150
Section 1: Short summary
150
151
~~~~~~~~~~~~~~~~~~~~~~~~
151
152
152
- The short summary is a single sentence that express what the function does in a
153
- concise way.
153
+ The short summary is a single sentence that expresses what the function does in
154
+ a concise way.
154
155
155
156
The short summary must start with a capital letter, end with a dot, and fit in
156
157
a single line. It needs to express what the object does without providing
@@ -395,7 +396,7 @@ last two types, that need to be separated by the word 'or':
395
396
- float, decimal.Decimal or None
396
397
- str or list of str
397
398
398
- If `None ` is one of the accepted values, it always needs to be the last in
399
+ If `` None ` ` is one of the accepted values, it always needs to be the last in
399
400
the list.
400
401
401
402
.. _docstring.returns :
@@ -493,28 +494,28 @@ instead of at the beginning, it is good to let the users know about it.
493
494
To give an intuition on what can be considered related, here there are some
494
495
examples:
495
496
496
- * `loc ` and `iloc `, as they do the same, but in one case providing indices and
497
- in the other positions
498
- * `max ` and `min `, as they do the opposite
499
- * `iterrows `, `itertuples ` and `iteritems `, as it is easy that a user looking
500
- for the method to iterate over columns ends up in the method to iterate
501
- over rows, and vice-versa
502
- * `fillna ` and `dropna `, as both methods are used to handle missing values
503
- * `read_csv ` and `to_csv `, as they are complementary
504
- * `merge ` and `join `, as one is a generalization of the other
505
- * `astype ` and `pandas.to_datetime `, as users may be reading the documentation
506
- of `astype ` to know how to cast as a date, and the way to do it is with
507
- ` pandas.to_datetime `
508
- * `where ` is related to `numpy.where `, as its functionality is based on it
497
+ * `` loc `` and `` iloc `` , as they do the same, but in one case providing indices
498
+ and in the other positions
499
+ * `` max `` and `` min ` `, as they do the opposite
500
+ * `` iterrows `` , `` itertuples `` and `` iteritems `` , as it is easy that a user
501
+ looking for the method to iterate over columns ends up in the method to
502
+ iterate over rows, and vice-versa
503
+ * `` fillna `` and `` dropna ` `, as both methods are used to handle missing values
504
+ * `` read_csv `` and `` to_csv ` `, as they are complementary
505
+ * `` merge `` and `` join ` `, as one is a generalization of the other
506
+ * `` astype `` and `` pandas.to_datetime `` , as users may be reading the
507
+ documentation of `` astype `` to know how to cast as a date, and the way to do
508
+ it is with `` pandas.to_datetime ` `
509
+ * `` where `` is related to `` numpy.where ` `, as its functionality is based on it
509
510
510
511
When deciding what is related, you should mainly use your common sense and
511
512
think about what can be useful for the users reading the documentation,
512
513
especially the less experienced ones.
513
514
514
- When relating to other libraries (mainly `numpy `), use the name of the module
515
- first (not an alias like `np `). If the function is in a module which is not
516
- the main one, like `scipy.sparse `, list the full module (e.g.
517
- `scipy.sparse.coo_matrix `).
515
+ When relating to other libraries (mainly `` numpy ` `), use the name of the module
516
+ first (not an alias like `` np ` `). If the function is in a module which is not
517
+ the main one, like `` scipy.sparse ` `, list the full module (e.g.
518
+ `` scipy.sparse.coo_matrix ` `).
518
519
519
520
This section, as the previous, also has a header, "See Also" (note the capital
520
521
S and A). Also followed by the line with hyphens, and preceded by a blank line.
@@ -579,8 +580,8 @@ placed in the last position. As often, people understand concepts better
579
580
with examples, than with accurate explanations.
580
581
581
582
Examples in docstrings, besides illustrating the usage of the function or
582
- method, they must be valid Python code, that in a deterministic way returns
583
- the presented output, and that can be copied and run by users.
583
+ method, must be valid Python code, that in a deterministic way returns the
584
+ presented output, and that can be copied and run by users.
584
585
585
586
They are presented as a session in the Python terminal. `>>> ` is used to
586
587
present code. `... ` is used for code continuing from the previous line.
@@ -590,7 +591,7 @@ be added with blank lines before and after them.
590
591
591
592
The way to present examples is as follows:
592
593
593
- 1. Import required libraries (except `numpy ` and `pandas `)
594
+ 1. Import required libraries (except `` numpy `` and `` pandas ` `)
594
595
595
596
2. Create the data required for the example
596
597
@@ -649,7 +650,7 @@ A simple example could be:
649
650
650
651
The examples should be as concise as possible. In cases where the complexity of
651
652
the function requires long examples, is recommended to use blocks with headers
652
- in bold. Use double star \*\* to make a text bold, like in \*\ * this example\*\* .
653
+ in bold. Use double star `` ** `` to make a text bold, like in `` * *this example** `` .
653
654
654
655
.. _docstring.example_conventions :
655
656
@@ -671,28 +672,29 @@ and avoiding aliases. Avoid excessive imports, but if needed, imports from
671
672
the standard library go first, followed by third-party libraries (like
672
673
matplotlib).
673
674
674
- When illustrating examples with a single `Series ` use the name `s `, and if
675
- illustrating with a single `DataFrame ` use the name `df `. For indices, `idx `
676
- is the preferred name. If a set of homogeneous `Series ` or `DataFrame ` is used,
677
- name them `s1 `, `s2 `, `s3 `... or `df1 `, `df2 `, `df3 `... If the data is not
678
- homogeneous, and more than one structure is needed, name them with something
679
- meaningful, for example `df_main ` and `df_to_join `.
675
+ When illustrating examples with a single ``Series `` use the name ``s ``, and if
676
+ illustrating with a single ``DataFrame `` use the name ``df ``. For indices,
677
+ ``idx `` is the preferred name. If a set of homogeneous ``Series `` or
678
+ ``DataFrame `` is used, name them ``s1 ``, ``s2 ``, ``s3 ``... or ``df1 ``,
679
+ ``df2 ``, ``df3 ``... If the data is not homogeneous, and more than one structure
680
+ is needed, name them with something meaningful, for example ``df_main `` and
681
+ ``df_to_join ``.
680
682
681
683
Data used in the example should be as compact as possible. The number of rows
682
684
is recommended to be around 4, but make it a number that makes sense for the
683
- specific example. For example in the `head ` method, it requires to be higher
684
- than 5, to show the example with the default values. If doing the `mean `,
685
- we could use something like `[1, 2, 3] `, so it is easy to see that the
686
- value returned is the mean.
685
+ specific example. For example in the `` head ` ` method, it requires to be higher
686
+ than 5, to show the example with the default values. If doing the `` mean ``, we
687
+ could use something like `` [1, 2, 3] `` , so it is easy to see that the value
688
+ returned is the mean.
687
689
688
690
For more complex examples (groupping for example), avoid using data without
689
691
interpretation, like a matrix of random numbers with columns A, B, C, D...
690
692
And instead use a meaningful example, which makes it easier to understand the
691
693
concept. Unless required by the example, use names of animals, to keep examples
692
694
consistent. And numerical properties of them.
693
695
694
- When calling the method, keywords arguments `head(n=3) ` are preferred to
695
- positional arguments `head(3) `.
696
+ When calling the method, keywords arguments `` head(n=3) ` ` are preferred to
697
+ positional arguments `` head(3) ` `.
696
698
697
699
**Good: **
698
700
@@ -827,15 +829,13 @@ Getting the examples pass the doctests in the validation script can sometimes
827
829
be tricky. Here are some attention points:
828
830
829
831
* 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
+ imported as `` import pandas as pd `` and `` import numpy as np `` ) and define
833
+ all variables you use in the example.
832
834
833
835
* Try to avoid using random data.
834
836
835
837
* If you have a code snippet that wraps multiple lines, you need to use '...'
836
- on the continued lines:
837
-
838
- ::
838
+ on the continued lines: ::
839
839
840
840
>>> df = pd.DataFrame([[1, 2, 3], [4, 5, 6]], index=['a', 'b', 'c'],
841
841
... columns=['A', 'B'])
@@ -853,12 +853,12 @@ be tricky. Here are some attention points:
853
853
represenation), you can use ``... `` to represent this part.
854
854
855
855
If you want to show that ``s.plot() `` returns a matplotlib AxesSubplot object,
856
- this will fail the doctest::
856
+ this will fail the doctest ::
857
857
858
858
>>> s.plot()
859
859
<matplotlib.axes._subplots.AxesSubplot at 0x7efd0c0b0690>
860
860
861
- However, you can do (notice the comment that needs to be added)::
861
+ However, you can do (notice the comment that needs to be added) ::
862
862
863
863
>>> s.plot() # doctest: +ELLIPSIS
864
864
<matplotlib.axes._subplots.AxesSubplot at ...>
@@ -870,7 +870,7 @@ Plots in examples
870
870
^^^^^^^^^^^^^^^^^
871
871
872
872
There are some methods in pandas returning plots. To render the plots generated
873
- by the examples in the documentation, the `.. plot:: ` directive exists.
873
+ by the examples in the documentation, the `` .. plot:: ` ` directive exists.
874
874
875
875
To use it, place the next code after the "Examples" header as shown below. The
876
876
plot will be generated automatically when building the documentation.
0 commit comments