-
-
Couldn't load subscription status.
- Fork 19.2k
DOC: Fixed the doctsring for _set_axis_name (GH 22895) #22969
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
DOC: Fixed the doctsring for _set_axis_name (GH 22895) #22969
Conversation
| Hello @bkjchoi72! Thanks for updating the PR.
Comment last updated on October 09, 2018 at 08:34 Hours UTC |
Codecov Report
@@ Coverage Diff @@ ## master #22969 +/- ## ========================================== + Coverage 92.28% 92.28% +<.01% ========================================== Files 161 161 Lines 51451 51452 +1 ========================================== + Hits 47483 47484 +1 Misses 3968 3968
Continue to review full report at Codecov.
|
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.
Nice!
| @bkjchoi72 : FYI, you don't have to close your PR (#22968) and open a new if there are issues with it. You can keep making commits to the existing PR and fix them there. |
pandas/core/generic.py Outdated
| The axis to set the label. The value 0 or 'index' specifies index, | ||
| and the value 1 or 'columns' specifies columns. | ||
| inplace : bool, default False | ||
| Whether to modify `self` directly or return a copy. |
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.
see what we use elsewhere for this
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.
There isn't great consistency for the description of inplace parameter. The most common and easy to understand I found is If True, do operation inplace and return None. I'll go with that one, and I'll change bool to boolean.
pandas/core/generic.py Outdated
| Examples | ||
| -------- | ||
| >>> df = pd.DataFrame({"A": [1, 2, 3]}) | ||
| >>> df._set_axis_name("foo") |
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 show what the current axis name is prior to setting it.
pandas/core/generic.py Outdated
| Examples | ||
| -------- | ||
| >>> df = pd.DataFrame({"A": [1, 2, 3]}) |
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 for updating the docstring @bkjchoi72, looking much better now, and it fixes the doctest, which was the main goal. Just one comment that would make this docstring even better, besides the comments in the previous review.
Do you mind adding a more real-world example? I know it's the original example, not yours, but setting the axis name to foo doesn't give a good idea of that the axis name is.
We use examples in the code with names of animals, and some property like the number of legs. Could you do something like that, and set the axis to animals or the meaningful name for the example?
If you can also change that in DataFrame.rename_axis() too, which has a example with foo as well, that would be great.
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 for the suggestion. I'll make those changes.
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.
looking good, just two small things
pandas/core/generic.py Outdated
| 0 dog 4 | ||
| 1 cat 4 | ||
| 2 monkey 2 | ||
| >>> df.rename_axis("id", axis="columns") |
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.
In this case, the concept id refers to name and legs, which does not make sense.
It could make more sense to have the name as the index, and then may be a column num_legs and a column num_arms and call the axis limbs.
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.
Makes sense
pandas/core/generic.py Outdated
| 0 1 4 | ||
| 1 2 5 | ||
| 2 3 6 | ||
| >>> df = pd.DataFrame({"name": ["dog", "cat", "monkey"], "legs": [4, 4, 2]}) |
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.
this is longer than 79 characters, isn't it?
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 example looks great. Added some more comments, minor things that can be improved, and then should be ready to be merged.
pandas/core/generic.py Outdated
| 1 2 5 | ||
| 2 3 6 | ||
| >>> df = pd.DataFrame({"num_legs": [4, 4, 2], | ||
| ... "num_arms": [0, 0, 2]}, |
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 indentation of this line looks wrong
pandas/core/generic.py Outdated
| def _set_axis_name(self, name, axis=0, inplace=False): | ||
| """ | ||
| Alter the name or names of the axis. | ||
| Alter the label(s) of the axis. |
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.
This doesn't seem correct. Altering the labels would be changing the names of the columns, not the name of the axis itself.
And small thing, but alter doesn't necessarily need to be correct. If the axis doesn't have a name, it's setting it, but not altering. Set would be better I think.
pandas/core/generic.py Outdated
| 0 or 'index' for the index; 1 or 'columns' for the columns | ||
| inplace : bool | ||
| whether to modify `self` directly or return a copy | ||
| Labels(s) to set. |
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.
Same as before, label is the names of each individual column, not the name of the axis
pandas/core/generic.py Outdated
| Returns | ||
| ------- | ||
| renamed : same type as caller or None if inplace=True | ||
| Series, DataFrame, Panel, or None |
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 remove Panel here. While it's correct, Panel it's already deprecated and will disappear in couple of months, so not worth having it.
pandas/core/generic.py Outdated
| cat 4 | ||
| monkey 2 | ||
| >>> df.index = pd.MultiIndex.from_product( | ||
| ... [["mammal"], ['dog', 'cat', 'monkey']]) |
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 try to present this using a better indentation. I think this is not pep8 compatible
| @jreback @datapythonista Thanks for the patience guys. Let me make adjustments based on your feedback. |
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.
lgtm, thanks @bkjchoi72 for the fixes
| @bkjchoi72 can you take a look at the errors in travis please? they look like genuine errors in your PR. |
| @datapythonista The tests are fixed. Thanks for your time and guidance! |
| did you run |
| @datapythonista I don't see indentation errors related to my changes. I modified lines 1120 - 1191 and 1207 -1258. Below is the output of None in the range that I modified shows up from my end. Do you have specific line numbers that are violating pep8 standards? |
pandas/core/generic.py Outdated
| 2 3 6 | ||
| >>> df = pd.DataFrame({"num_legs": [4, 4, 2], | ||
| ... "num_arms": [0, 0, 2]}, | ||
| ... ["dog", "cat", "monkey"]) |
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.
this is where I think the ['dog'... should be indented as the {, and not one more. Not sure why is not being captured.
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.
It seems like 1173 and 1174 both need to be aligned with {
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.
doesn't make sense to me, I think it's a flake8 bug, but let's leave it like this is the linting fails with what I think it's the right indentaiton.
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.
Actually, it makes sense to adjust line 1174 only since the argument is composed of two things: dict and list
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.
flake8 still passes with the suggested indentation.
| Sorry for the delay @bkjchoi72, can you fix the conflicts, so we can merge? |
| @bkjchoi72, do you have time to fix the conflicts? |
| @datapythonista I'll get to it this weekend. |
| thanks @bkjchoi72 |
| @datapythonista I was on vacation for the past 10 days, so just saw this now. All looks good to me. |
Fixed the docstring of the function
_set_axis_nameinpandas/core/generic.pyCloses #22895