-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Add examples to documentation for DataFrame.swaplevel #40269
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
Add examples to documentation for DataFrame.swaplevel #40269
Conversation
thordisstella
commented
Mar 6, 2021
- [x ] closes add example to swaplevel MarcoGorelli/pyladieslondon-sprints#13
- tests added / passed
- Ensure all linting tests pass, see here for how to run them
- whatsnew entry
Hello @thordisstella! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2021-03-11 20:58:01 UTC |
157db00
to
fbb1755
Compare
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.
Really nice example @thordisstella , thanks, have just left some minor comments
in a similar manner. Note that column-wise is the default behaviour. | ||
By not supplying any arguments for i and j, we swap the last and second to | ||
last indices. | ||
>>> df.swaplevel() |
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.
can you leave a blank line before this?
pandas/core/frame.py
Outdated
>>> df = pd.DataFrame({'Grade':['A','B','A','C']}, | ||
... index=[['Final exam', 'Final exam', 'Coursework', | ||
... 'Coursework'], | ||
... ['History','Geography','History','Geography'], | ||
... ['January','February','March','April']]) |
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.
Could you reformat this according to the black
formatter (to be consistent with most of the rest of the docs...we should probably run blackdoc
, but that's for a separate issue/PR)
pandas/core/frame.py
Outdated
We can also define explicitly which indices we want to swap by supplying values | ||
for both i and j. Here, we for example swap the first and second indices. | ||
|
||
>>> df.swaplevel(0,1) |
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.
can you add a space between the arguments? (swaplevel(0, 1)
)
fbb1755
to
3577010
Compare
Thanks for the review @MarcoGorelli! I addressed the comments, but when I ran |
Hey @thordisstella , thanks for updating (and happy IWD!)! Sorry, I was unclear - # t.py
"""
>>> df = pd.DataFrame({'Grade':['A','B','A','C']},
... index=[['Final exam', 'Final exam', 'Coursework',
... 'Coursework'],
... ['History','Geography','History','Geography'],
... ['January','February','March','April']])
""" , running pip install blackdoc
blackdoc t.py --line-length 80 and then pasting the reformatted version back into this docstring of Finally, you should run $ python scripts/validate_docstrings.py pandas.DataFrame.swaplevel and check it doesn't throw any extra errors compared to when run on |
3577010
to
55832da
Compare
Thanks, and belated happy IWD to you too! 😊 Thanks for the clarification - I've updated the PR as you suggested so hopefully we should be good now 🤞 |
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 - there's just a blank line which needs removing (else it'll fail scripts/validate_docstrings.py
), rest looks good
pandas/core/frame.py
Outdated
Geography Coursework April C | ||
|
||
""" |
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.
Geography Coursework April C | |
""" | |
Geography Coursework April C | |
""" |
55832da
to
302a2f0
Compare
Hi @thordisstella - looks good, CI failures should be unrelated, could you fetch and merge upstream/master please? |
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.
Pending green, looks good to me!
(a follow-up PR to add a similar example to Series.swaplevel
and/or make a shared docstring would be welcome if you want)
Thanks for the review, all the advice and for merging this @MarcoGorelli ! And apologies for the delay in reacting to your last comment. I'll take a look at the follow up PR you suggested either later this week or next week :) |