Skip to content

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

Merged
merged 2 commits into from
Mar 17, 2020

Conversation

dan1261
Copy link
Contributor

@dan1261 dan1261 commented Mar 8, 2020

The main contribution is to add a docstring with examples for the "name" property of the Series object. Also corrected some typos and grammatical points in the "pandas docstring guide".

The type hint gives the type as "Label" and I could not find any other reference to a custom type defined in pandas._typing which was explicitly mentioned in the docs (instead they specify "str" or "int" or somesuch), so I chose "Label (int, str or other hashable object)".

Further I chose "whenever displaying the Series in the interpreter" as clearer alternative to "when invoking the repr method" or a similar precise statement.

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool thanks for the cleanups. Minor things

1 2
2 3
dtype: int64
>>> s1.name = "Numbers"
Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2020-03-14 (1)

Though I changed this here's a screenshot of the new version

1 2 2
2 3 3

The name of a Series also persists through some transformations.
Copy link
Member

Choose a reason for hiding this comment

The 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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I've removed this part

@WillAyd WillAyd added the Docs label Mar 9, 2020

Returns
-------
Label (int, str or other hashable object).
Copy link
Member

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:

Returns
-------
label
    The name of the Series, which is the column name if it's part of a DataFrame.

Copy link
Contributor Author

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?


Examples
--------
>>> s1 = pd.Series([1, 2, 3], dtype=np.int64)
Copy link
Member

Choose a reason for hiding this comment

The 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:

  • Create a series with the name as Series(..., name='whatever'), and then set to something else
  • Create a small dataframe (two columns, three rows), and check the name of one of the columns

I think this will be easier for users to understand the main usage of the name attribute. While your examples are good and probably more accurate than this, I think users visiting this page may in most cases appreciate something more basic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

@datapythonista datapythonista left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, really nice example, thanks a lot for the work on this @dan1261.

For future PRs, we usually prefer to have atomic PRs, and not mix things in the same PR. So, in this case would be preferred to have one for the improvements to the contributing doc, and another for the docstring. If you want to split it, feel free to, but I'm happy to get this merged (doc PRs are very unlikely to be reverted, one of the main reasons for having atomic PRs).

@dan1261
Copy link
Contributor Author

dan1261 commented Mar 14, 2020

Thanks @datapythonista , I considered making two separate PRs - in future I'll follow your advice!

@WillAyd WillAyd added this to the 1.1 milestone Mar 17, 2020
@WillAyd WillAyd merged commit eb02a3b into pandas-dev:master Mar 17, 2020
@WillAyd
Copy link
Member

WillAyd commented Mar 17, 2020

Great thanks @dan1261

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants