Skip to content

DOC add example of Series.index #51842

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 27 commits into from
Apr 16, 2023
Merged

DOC add example of Series.index #51842

merged 27 commits into from
Apr 16, 2023

Conversation

ggold7046
Copy link
Contributor

Added the example section.

  • closes #xxxx (Replace xxxx with the GitHub issue number)
  • Tests added and passed if fixing a bug or adding a new feature
  • All code checks passed.
  • Added type annotations to new arguments/methods/functions.
  • Added an entry in the latest doc/source/whatsnew/vX.X.X.rst file if fixing a bug or adding a new feature.

Added the example section.
@ggold7046
Copy link
Contributor Author

Hi @DeaMariaLeon , could you please help me in this issue ?

The error says ---> Error: None:None:GL01:pandas.Series.index:Docstring text (summary) should start in the line immediately after the opening quotes (not in the same line, or leaving a blank line in between). But I saw in the series.py file ; every summary is written after leaving a blank line.

And this one too https://github.com/pandas-dev/pandas/actions/runs/4365774703/jobs/7634865667
I don't see the trailing whitespaces. I don't understand which line is too long.

Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

hi @ggold7046

before fixing the validation errors - did you try building this docstring locally? could you post a screenshot of how it looks please?

@MarcoGorelli MarcoGorelli changed the title Update series.py DOC add example of Series.index Mar 9, 2023
@ggold7046
Copy link
Contributor Author

I used gitpod for development https://pandas.pydata.org/docs/dev/development/contributing_gitpod.html and write the docstring and tested with python scripts/validate_docstrings.py pandas.Series.index . As most of the test were passed and there was no "no example section found" error, I pulled a request.

@mroeschke mroeschke added the Docs label Mar 9, 2023
Updated the docstring.
Updated the docstring.
New update.
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.

Thanks @ggold7046 for the contribution, added some comments. As Marco says, you'll need to build the documentation locally. You have instructions on the contrubuting documentation.

Comment on lines 5995 to 5996
axis=0, doc="The index (axis labels) of the Series."
"""
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 make this a single text, not concatenating in this way please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, but didn't understand. You mean like this ?
axis=0, doc="The index (axis labels) of the Series." """ A one-dimensional ndarray with hashable type axis labels. """

or this

axis=0, doc="The index (axis labels) of the Series."
""" A one-dimensional ndarray with hashable type axis labels. """

Copy link
Contributor

Choose a reason for hiding this comment

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

@ggold7046

Could you please use triple backticks to format code blocks? Without it, your question is really hard to read.

What @datapythonista means is that you have two strings here that will be concatenated:

a = (
    "The index [...]"
    """

    A one-dimensional [...]
    """
)
print(a)
The index [...]

    A one-dimensional [...]
    

Since you already have a multiline string (triple quotes), you can just merge the two:

b = """\
The index [...]

A one-dimensional [...]
"""
print(b)
The index [...]

A one-dimensional [...]

**Use the Series.index attribute to set the index label for
the given Series object.**

>>> s = pd.Series(['Kolkata', 'Chicago', 'Toronto', 'Lisbon'])
Copy link
Member

Choose a reason for hiding this comment

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

This example is not very realistic and confusing with the City 1, City 2 labels. Maybe something like using the city as index and then making the value a feature like population, average temperature... would make more sense.

Also, since here you're just showing the .index accessor, better create the index with Series(..., index=...) and simply show that your_series.index returns the index.

Comment on lines 6000 to 6004
Pandas Series.index attribute is used to get or set the index labels
of the given Series object.The object supports both
integer- and label-based indexing and provides a host of methods for
performing operations involving the index.
The labels need not be unique but must be of the hashable type.
Copy link
Member

Choose a reason for hiding this comment

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

I think it makes more sense to link to the indexing user guide that try to explain what's indexing in a single paragraph 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.

So, I have to add a see also section and mention this link ? https://pandas.pydata.org/docs/reference/api/pandas.Index.html

@pmeier
Copy link
Contributor

pmeier commented Mar 23, 2023

@ggold7046
Copy link
Contributor Author

Hi everyone,
I've updated the docstring and uploaded the rendered html docs. I couldn't posted the full doc as a single page because it was long. That is why I'm uploading in 2 pieces.

pandas1

pandas2

Copy link
Contributor

@pmeier pmeier left a comment

Choose a reason for hiding this comment

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

There are currently three CI jobs failing:

  1. https://github.com/pandas-dev/pandas/actions/runs/4584805993/jobs/8096531909?pr=51842#step:4:274
  2. https://github.com/pandas-dev/pandas/actions/runs/4584805993/jobs/8096531828?pr=51842#step:8:12
  3. https://github.com/pandas-dev/pandas/actions/runs/4584805987/jobs/8096531417?pr=51842#step:6:68

They are all related to the formatting of the docstring you wrote. Let's go through them one by one inline below.

Note that all these things are very project specific. Every project defines their own style and one has to abide by that.

ggold7046 and others added 4 commits April 4, 2023 15:53
Copy link
Contributor

@pmeier pmeier left a comment

Choose a reason for hiding this comment

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

You have more trailing whitespace.

@ggold7046 ggold7046 requested a review from pmeier April 4, 2023 13:51
ggold7046 and others added 2 commits April 4, 2023 19:57
@ggold7046 ggold7046 requested a review from pmeier April 7, 2023 18:26
@ggold7046
Copy link
Contributor Author

ggold7046 commented Apr 10, 2023

This is the error I'm getting while running the pre-commit install command in gitpod.

Error installing pre-commit
(pandas-dev) gitpod > /workspace/pandas $ pre-commit install An unexpected error has occurred: PermissionError: [Errno 13] Permission denied: '/home/gitpod/.cache/pre-commit' Traceback (most recent call last): File "/home/gitpod/mambaforge3/envs/pandas-dev/lib/python3.8/site-packages/pre_commit/error_handler.py", line 73, in error_handler yield File "/home/gitpod/mambaforge3/envs/pandas-dev/lib/python3.8/site-packages/pre_commit/main.py", line 340, in main store = Store() File "/home/gitpod/mambaforge3/envs/pandas-dev/lib/python3.8/site-packages/pre_commit/store.py", line 51, in __init__ os.makedirs(self.directory, exist_ok=True) File "/home/gitpod/mambaforge3/envs/pandas-dev/lib/python3.8/os.py", line 223, in makedirs mkdir(name, mode) PermissionError: [Errno 13] Permission denied: '/home/gitpod/.cache/pre-commit'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/gitpod/mambaforge3/envs/pandas-dev/bin/pre-commit", line 11, in
sys.exit(main())
File "/home/gitpod/mambaforge3/envs/pandas-dev/lib/python3.8/site-packages/pre_commit/main.py", line 405, in main
raise AssertionError(
File "/home/gitpod/mambaforge3/envs/pandas-dev/lib/python3.8/contextlib.py", line 131, in exit
self.gen.throw(type, value, traceback)
File "/home/gitpod/mambaforge3/envs/pandas-dev/lib/python3.8/site-packages/pre_commit/error_handler.py", line 81, in error_handler
_log_and_exit(msg, ret_code, e, traceback.format_exc())
File "/home/gitpod/mambaforge3/envs/pandas-dev/lib/python3.8/site-packages/pre_commit/error_handler.py", line 31, in _log_and_exit
storedir = Store().directory
File "/home/gitpod/mambaforge3/envs/pandas-dev/lib/python3.8/site-packages/pre_commit/store.py", line 51, in init
os.makedirs(self.directory, exist_ok=True)
File "/home/gitpod/mambaforge3/envs/pandas-dev/lib/python3.8/os.py", line 223, in makedirs
mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/home/gitpod/.cache/pre-commit'
(pandas-dev) gitpod > /workspace/pandas $

Though when I do pip install pre-commit , it says requirement satisfied.

@pmeier
Copy link
Contributor

pmeier commented Apr 11, 2023

@ggold7046 Please make it a habit to wrap terminal output in triple backticks to get proper formatting. The traceback is painful to read the way you posted it.

The error you are facing has little to do with pre-commit. You seem to have no permissions to write to the /home/gitpod/.cache directory. I don't use GitPod so I can't help you there. However, if this a general thing, the pandas team might be interested in this report given that they promote GitPod as a way to develop on. Thus, all the tools should work. You can open a new issue detailing your problem.

For this PR though, you don't need pre-commit anymore. The CI error is formatting related, but this is nothing pre-commit, or rather the tools it invokes, can fix automatically. Fix the "Code Checks / Docstring validation" CI job and after that we should be done. The actual doc build failed to an unrelated issue. Hints:

  1. The summary of the docstring is the first line that includes content.
  2. RST "ignores" single line breaks and you need an actual blank line to separate two paragraphs.
  3. You had this issue before and I suggested a solution to it in a comment that is now marked as "resolved".

@ggold7046
Copy link
Contributor Author

Hi @pmeier , both the code checks/pre-coomit and code checks/docstring validation have been passed at last. 😫 .

@github-actions
Copy link
Contributor

Website preview of this PR available at: https://pandas.pydata.org/preview/51842/

Copy link
Contributor

@pmeier pmeier left a comment

Choose a reason for hiding this comment

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

Awesome @ggold7046. Docstring looks good formatting wise and CI is happy as well. Now someone from the pandas team needs to review the content.

@ggold7046
Copy link
Contributor Author

ggold7046 commented Apr 12, 2023

Hi @MarcoGorelli , @datapythonista, @mroeschke could you have a review on this please ? I hope this time this PR gets merged.

Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

thank for working on this - got a minor comment, but this looks like it's close

can you also remove this line

pandas.Series.index \

please?

doc="""
The index (axis labels) of the Series.

Get the index (row labels) of the Series.
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure what this sentence adds - why not move the paragraph starting with

The index of a Series is used to label and identify each element of the

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

to here?

I did not get it. Could you please tell me where to move ?

Copy link
Member

Choose a reason for hiding this comment

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

where I left the comment. i.e. instead of this "Get the index (row labels) of the Series." paragraph

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @MarcoGorelli , I tried to move that paragraph The index of a Series is used to label and identify each element of the to the first line replacing Get the index (row labels) of the Series., but it failed the CI. In the pandas documentation it is said that the first summary line should be a single meaning full line. And then an extending summary. So can we keep that single line as it is and can I revert back to the old commit ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure what you mean here @ggold7046. The summary, i.e.

The index (axis labels) of the Series.

is a single line. The CI fails because you again included trailing white space in the blank line.

@ggold7046
Copy link
Contributor Author

thank for working on this - got a minor comment, but this looks like it's close

can you also remove this line

pandas.Series.index \

please?

Hi @MarcoGorelli , I'm unable to edit this file in github page. The edit button is greyed out.

@ggold7046 ggold7046 requested a review from MarcoGorelli April 13, 2023 09:54
@pmeier
Copy link
Contributor

pmeier commented Apr 13, 2023

I'm unable to edit this file in github page. The edit button is greyed out.

You should edit this file inside your PR. So judging from the comments above, inside the GitPod environment.

@ggold7046
Copy link
Contributor Author

ggold7046 commented Apr 13, 2023

@MarcoGorelli, @datapythonista, I have updated both the files. Could you please take a look and tell me if everything is fine ?

Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

Well done, thanks for sticking with this for so long

I'll leave open a bit in case Marc has other comments, and if not then we can merge

@MarcoGorelli MarcoGorelli added this to the 2.1 milestone Apr 13, 2023
@ggold7046
Copy link
Contributor Author

Hi @datapythonista , could you please have a look at this PR so that it could be merged ?

@datapythonista datapythonista merged commit aa4a039 into pandas-dev:main Apr 16, 2023
@datapythonista
Copy link
Member

Thanks @ggold7046 and the rest, very nice work.

@ggold7046 ggold7046 deleted the patch-1 branch April 17, 2023 06:01
@ggold7046
Copy link
Contributor Author

ggold7046 commented Apr 17, 2023

Hello @datapythonista , @MarcoGorelli thank for your time and support. And many many thanks for @pmeier for sticking with me for so long on this.

mroeschke pushed a commit that referenced this pull request Apr 19, 2023
Update series.py

DOC add example of Series.index #51842 . A newline between the text and the code is missing.
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.

5 participants