-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: Added docstring for Series.name and corrected docstring guide #32549
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -435,6 +435,51 @@ def dtypes(self) -> DtypeObj: | |
|
||
@property | ||
def name(self) -> Label: | ||
""" | ||
Return the name of the Series. | ||
|
||
The name of a Series becomes its index or column name if it is used | ||
to form a DataFrame. It is also used whenever displaying the Series | ||
using the interpreter, and persists through some transformations. | ||
|
||
Returns | ||
------- | ||
Label (int, str or other hashable object). | ||
|
||
See Also | ||
-------- | ||
Index.name : Equivalent property for Index object. | ||
|
||
Examples | ||
-------- | ||
>>> s1 = pd.Series([1, 2, 3], dtype=np.int64) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice work @dan1261. I agree with @WillAyd, I think the examples don't represent the common uses of pandas, and that they can somehow confuse users. What do you think about having two simple examples:
I think this will be easier for users to understand the main usage of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great, I've followed your suggestions, what do you think? I was originally motivated by trying to concat some Series in this manner which led to the example. |
||
>>> s1 | ||
0 1 | ||
1 2 | ||
2 3 | ||
dtype: int64 | ||
>>> s1.name = "Numbers" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you post a screenshot of the built doc? Might need a newline here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
>>> s1 | ||
0 1 | ||
1 2 | ||
2 3 | ||
Name: Numbers, dtype: int64 | ||
>>> s2 = s1.copy() | ||
>>> s2.name = "More Numbers" | ||
>>> pd.concat([s1, s2], axis=1) | ||
Numbers More Numbers | ||
0 1 1 | ||
1 2 2 | ||
2 3 3 | ||
|
||
The name of a Series also persists through some transformations. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Appreciate what you are trying to do here but typically best to avoid vagaries like this in the docstring. I think can just delete this part altogether unless this is completely standard (don't think it is, but maybe should be) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, I've removed this part |
||
|
||
>>> s1.cumsum() | ||
0 1 | ||
1 3 | ||
2 6 | ||
Name: Numbers, dtype: int64 | ||
""" | ||
return self._name | ||
|
||
@name.setter | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The format of Returns is the type first (without an ending period), and the description in the next line:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I've changed the format. I don't see any other reference to custom pandas types like label, does capitalisation matter?