Skip to content

Commit deeacba

Browse files
Working on the pandas doc guide
1 parent ddf382c commit deeacba

File tree

6 files changed

+692
-1
lines changed

6 files changed

+692
-1
lines changed
18.7 KB
Binary file not shown.
1.7 KB
Binary file not shown.

docs/pandas-doc/build/_sources/contents.rst.txt

Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,237 @@ about reStructuredText can be found in:
7272

7373
The rest of this document will summarize all the above guides, and will
7474
provide additional convention specific to the pandas project.
75+
76+
Writing a docstring
77+
-------------------
78+
79+
General rules
80+
~~~~~~~~~~~~~
81+
82+
Docstrings must be defined with three double-quotes. No blank lines should be
83+
left before or after the docstring. The text starts immediately after the
84+
opening quotes (not in the next line). The closing quotes have their own line
85+
(and are not added at the end of the last sentence).
86+
87+
**Good:**
88+
89+
.. code-block:: python
90+
91+
def func():
92+
"""Some function.
93+
94+
With a good docstring.
95+
"""
96+
foo = 1
97+
bar = 2
98+
return foo + bar
99+
100+
**Bad:**
101+
102+
.. code-block:: python
103+
104+
def func():
105+
106+
"""
107+
Some function.
108+
109+
With several mistakes in the docstring.
110+
111+
It has a blank like after the signature `def func():`.
112+
113+
The text 'Some function' should go in the same line as the
114+
opening quotes of the docstring, not in the next line.
115+
116+
There is a blank line between the docstring and the first line
117+
of code `foo = 1`.
118+
119+
The closing quotes should be in the next line, not in this one."""
120+
121+
foo = 1
122+
bar = 2
123+
return foo + bar
124+
125+
Section 1: Short summary
126+
~~~~~~~~~~~~~~~~~~~~~~~~
127+
128+
The short summary is a single sentence that express what the function does in a
129+
concise way.
130+
131+
The short summary must start with a verb infinitive, end with a dot, and fit in
132+
a single line. It needs to express what the function does without providing
133+
details.
134+
135+
**Good:**
136+
137+
.. code-block:: python
138+
139+
def astype(dtype):
140+
"""Cast Series type.
141+
142+
This section will provide further details.
143+
"""
144+
pass
145+
146+
**Bad:**
147+
148+
.. code-block:: python
149+
150+
def astype(dtype):
151+
"""Casts Series type.
152+
153+
Verb in third-person of the present simple, should be infinitive.
154+
"""
155+
pass
156+
157+
def astype(dtype):
158+
"""Method to cast Series type.
159+
160+
Does not start with verb.
161+
"""
162+
pass
163+
164+
def astype(dtype):
165+
"""Cast Series type
166+
167+
Missing dot at the end.
168+
"""
169+
pass
170+
171+
def astype(dtype):
172+
"""Cast Series type from its current type to the new type defined in
173+
the parameter dtype.
174+
175+
Summary is too verbose and doesn't fit in a single line.
176+
"""
177+
pass
178+
179+
Section 2: Extended summary
180+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
181+
182+
The extended summary provides details on what the function does. It should not
183+
go into the details of the parameters, or discuss implementation notes, which
184+
go in other sections.
185+
186+
A blank line is left between the short summary and the extended summary. And
187+
every paragraph in the extended summary is finished by a dot.
188+
189+
.. code-block:: python
190+
191+
def unstack():
192+
"""Pivot a row index to columns.
193+
194+
When using a multi-index, a level can be pivoted so each value in
195+
the index becomes a column. This is especially useful when a subindex
196+
is repeated for the main index, and data is easier to visualize as a
197+
pivot table.
198+
199+
The index level will be automatically when added as columns.
200+
"""
201+
pass
202+
203+
Section 3: Parameters
204+
~~~~~~~~~~~~~~~~~~~~~
205+
206+
The details of the parameters will be added in this section. This section has
207+
the title "Parameters", followed by a line with a hyphen under each letter of
208+
the word "Parameters". A blank line is left before the section title, but not
209+
after, and not between the line with the word "Parameters" and the one with
210+
the hyphens.
211+
212+
After the title, each parameter in the signature must be documented, including
213+
`*args` and `**kwargs`, but not `self`.
214+
215+
The parameters are defined by their name, followed by a space, a colon, another
216+
space, and the type (or type). Note that the space between the name and the
217+
colon is important. Types are not defined for `*args` and `**kwargs`, but must
218+
be defined for all other parameters. After the parameter definition, it is
219+
required to have a line with the parameter description, which is indented, and
220+
can have multiple lines. The description must start with a capital letter, and
221+
finish with a dot.
222+
223+
**Good:**
224+
225+
.. code-block:: python
226+
227+
class Series:
228+
def plot(kind, **kwargs):
229+
"""Generate a plot.
230+
231+
Render the data in the Series as a matplotlib plot of the
232+
specified kind.
233+
234+
Parameters
235+
----------
236+
kind : str
237+
Kind of matplotlib plot.
238+
**kwargs
239+
These parameters will be passed to the matplotlib plotting
240+
function.
241+
"""
242+
243+
**Bad:**
244+
245+
.. code-block:: python
246+
247+
class Series:
248+
def plot(kind, **kwargs):
249+
"""Generate a plot.
250+
251+
Render the data in the Series as a matplotlib plot of the
252+
specified kind.
253+
254+
Note the blank line between the parameters title and the first
255+
parameter. Also, not that after the name of the parameter `kind`
256+
and before the colo, a space is missing.
257+
258+
Also, note that the parameter descriptions do not start with a
259+
capital letter, and do not finish with a dot.
260+
261+
Finally, the `**kwargs` is missing.
262+
263+
Parameters
264+
----------
265+
266+
kind: str
267+
kind of matplotlib plot
268+
"""
269+
270+
Parameter types
271+
^^^^^^^^^^^^^^^
272+
273+
When specifying the parameter types, Python built-in data types can be used
274+
directly:
275+
276+
- int
277+
- float
278+
- str
279+
280+
For complex types, define the subtypes:
281+
282+
- list of int
283+
- dict of str : int
284+
- tuple of (str, int, int)
285+
- set of str
286+
287+
If the type is defined in a Python module, the module must be specified:
288+
289+
- datetime.date
290+
- datetime.datetime
291+
- decimal.Decimal
292+
293+
If the type is in a package, the module must be equally specified:
294+
295+
- numpy.ndarray
296+
- scipy.sparse.coo_matrix
297+
298+
If the type is a pandas type, also specify pandas:
299+
300+
- pandas.Series
301+
- pandas.DataFrame
302+
303+
If more than one type is accepted, separate them by commas, except the
304+
last two types, that need to be separated by the word 'or':
305+
306+
- int or float
307+
- float, decimal.Decimal or None
308+
- str or list of str

0 commit comments

Comments
 (0)