Skip to content

Commit 911cb72

Browse files
dan1261SeeminSyed
authored andcommitted
DOC: Added docstring for Series.name and corrected docstring guide (pandas-dev#32549)
1 parent e6848eb commit 911cb72

File tree

2 files changed

+76
-30
lines changed

2 files changed

+76
-30
lines changed

doc/source/development/contributing_docstring.rst

+30-30
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Also, it is a common practice to generate online (html) documentation
1717
automatically from docstrings. `Sphinx <https://www.sphinx-doc.org>`_ serves
1818
this purpose.
1919

20-
Next example gives an idea on how a docstring looks like:
20+
The next example gives an idea of what a docstring looks like:
2121

2222
.. code-block:: python
2323
@@ -26,8 +26,8 @@ Next example gives an idea on how a docstring looks like:
2626
Add up two integer numbers.
2727
2828
This function simply wraps the `+` operator, and does not
29-
do anything interesting, except for illustrating what is
30-
the docstring of a very simple function.
29+
do anything interesting, except for illustrating what
30+
the docstring of a very simple function looks like.
3131
3232
Parameters
3333
----------
@@ -56,14 +56,14 @@ Next example gives an idea on how a docstring looks like:
5656
"""
5757
return num1 + num2
5858
59-
Some standards exist about docstrings, so they are easier to read, and they can
60-
be exported to other formats such as html or pdf.
59+
Some standards regarding docstrings exist, which make them easier to read, and allow them
60+
be easily exported to other formats such as html or pdf.
6161

6262
The first conventions every Python docstring should follow are defined in
6363
`PEP-257 <https://www.python.org/dev/peps/pep-0257/>`_.
6464

65-
As PEP-257 is quite open, and some other standards exist on top of it. In the
66-
case of pandas, the numpy docstring convention is followed. The conventions is
65+
As PEP-257 is quite broad, other more specific standards also exist. In the
66+
case of pandas, the numpy docstring convention is followed. These conventions are
6767
explained in this document:
6868

6969
* `numpydoc docstring guide <https://numpydoc.readthedocs.io/en/latest/format.html>`_
@@ -83,8 +83,8 @@ about reStructuredText can be found in:
8383
pandas has some helpers for sharing docstrings between related classes, see
8484
:ref:`docstring.sharing`.
8585

86-
The rest of this document will summarize all the above guides, and will
87-
provide additional convention specific to the pandas project.
86+
The rest of this document will summarize all the above guidelines, and will
87+
provide additional conventions specific to the pandas project.
8888

8989
.. _docstring.tutorial:
9090

@@ -101,9 +101,9 @@ left before or after the docstring. The text starts in the next line after the
101101
opening quotes. The closing quotes have their own line
102102
(meaning that they are not at the end of the last sentence).
103103

104-
In rare occasions reST styles like bold text or italics will be used in
104+
On rare occasions reST styles like bold text or italics will be used in
105105
docstrings, but is it common to have inline code, which is presented between
106-
backticks. It is considered inline code:
106+
backticks. The following are considered inline code:
107107

108108
* The name of a parameter
109109
* Python code, a module, function, built-in, type, literal... (e.g. ``os``,
@@ -235,8 +235,8 @@ The extended summary provides details on what the function does. It should not
235235
go into the details of the parameters, or discuss implementation notes, which
236236
go in other sections.
237237

238-
A blank line is left between the short summary and the extended summary. And
239-
every paragraph in the extended summary is finished by a dot.
238+
A blank line is left between the short summary and the extended summary.
239+
Every paragraph in the extended summary ends with a dot.
240240

241241
The extended summary should provide details on why the function is useful and
242242
their use cases, if it is not too generic.
@@ -542,19 +542,19 @@ first (not an alias like ``np``). If the function is in a module which is not
542542
the main one, like ``scipy.sparse``, list the full module (e.g.
543543
``scipy.sparse.coo_matrix``).
544544

545-
This section, as the previous, also has a header, "See Also" (note the capital
546-
S and A). Also followed by the line with hyphens, and preceded by a blank line.
545+
This section has a header, "See Also" (note the capital
546+
S and A), followed by the line with hyphens and preceded by a blank line.
547547

548548
After the header, we will add a line for each related method or function,
549549
followed by a space, a colon, another space, and a short description that
550-
illustrated what this method or function does, why is it relevant in this
551-
context, and what are the key differences between the documented function and
552-
the one referencing. The description must also finish with a dot.
550+
illustrates what this method or function does, why is it relevant in this
551+
context, and what the key differences are between the documented function and
552+
the one being referenced. The description must also end with a dot.
553553

554-
Note that in "Returns" and "Yields", the description is located in the
555-
following line than the type. But in this section it is located in the same
556-
line, with a colon in between. If the description does not fit in the same
557-
line, it can continue in the next ones, but it has to be indented in them.
554+
Note that in "Returns" and "Yields", the description is located on the line
555+
after the type. In this section, however, it is located on the same
556+
line, with a colon in between. If the description does not fit on the same
557+
line, it can continue onto other lines which must be further indented.
558558

559559
For example:
560560

@@ -587,7 +587,7 @@ Section 6: Notes
587587
~~~~~~~~~~~~~~~~
588588

589589
This is an optional section used for notes about the implementation of the
590-
algorithm. Or to document technical aspects of the function behavior.
590+
algorithm, or to document technical aspects of the function behavior.
591591

592592
Feel free to skip it, unless you are familiar with the implementation of the
593593
algorithm, or you discover some counter-intuitive behavior while writing the
@@ -600,15 +600,15 @@ This section follows the same format as the extended summary section.
600600
Section 7: Examples
601601
~~~~~~~~~~~~~~~~~~~
602602

603-
This is one of the most important sections of a docstring, even if it is
604-
placed in the last position. As often, people understand concepts better
605-
with examples, than with accurate explanations.
603+
This is one of the most important sections of a docstring, despite being
604+
placed in the last position, as often people understand concepts better
605+
by example than through accurate explanations.
606606

607607
Examples in docstrings, besides illustrating the usage of the function or
608-
method, must be valid Python code, that in a deterministic way returns the
609-
presented output, and that can be copied and run by users.
608+
method, must be valid Python code, that returns the given output in a
609+
deterministic way, and that can be copied and run by users.
610610

611-
They are presented as a session in the Python terminal. `>>>` is used to
611+
Examples are presented as a session in the Python terminal. `>>>` is used to
612612
present code. `...` is used for code continuing from the previous line.
613613
Output is presented immediately after the last line of code generating the
614614
output (no blank lines in between). Comments describing the examples can
@@ -636,7 +636,7 @@ A simple example could be:
636636
Return the first elements of the Series.
637637
638638
This function is mainly useful to preview the values of the
639-
Series without displaying the whole of it.
639+
Series without displaying all of it.
640640
641641
Parameters
642642
----------

pandas/core/series.py

+46
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,52 @@ def dtypes(self) -> DtypeObj:
435435

436436
@property
437437
def name(self) -> Label:
438+
"""
439+
Return the name of the Series.
440+
441+
The name of a Series becomes its index or column name if it is used
442+
to form a DataFrame. It is also used whenever displaying the Series
443+
using the interpreter.
444+
445+
Returns
446+
-------
447+
label (hashable object)
448+
The name of the Series, also the column name if part of a DataFrame.
449+
450+
See Also
451+
--------
452+
Series.rename : Sets the Series name when given a scalar input.
453+
Index.name : Corresponding Index property.
454+
455+
Examples
456+
--------
457+
The Series name can be set initially when calling the constructor.
458+
459+
>>> s = pd.Series([1, 2, 3], dtype=np.int64, name='Numbers')
460+
>>> s
461+
0 1
462+
1 2
463+
2 3
464+
Name: Numbers, dtype: int64
465+
>>> s.name = "Integers"
466+
>>> s
467+
0 1
468+
1 2
469+
2 3
470+
Name: Integers, dtype: int64
471+
472+
The name of a Series within a DataFrame is its column name.
473+
474+
>>> df = pd.DataFrame([[1, 2], [3, 4], [5, 6]],
475+
... columns=["Odd Numbers", "Even Numbers"])
476+
>>> df
477+
Odd Numbers Even Numbers
478+
0 1 2
479+
1 3 4
480+
2 5 6
481+
>>> df["Even Numbers"].name
482+
'Even Numbers'
483+
"""
438484
return self._name
439485

440486
@name.setter

0 commit comments

Comments
 (0)