-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DOC: Improve the docstring of String.str.zfill() #20864
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: Improve the docstring of String.str.zfill() #20864
Conversation
Codecov Report
@@ Coverage Diff @@
## master #20864 +/- ##
=========================================
Coverage ? 91.81%
=========================================
Files ? 153
Lines ? 49478
Branches ? 0
=========================================
Hits ? 45429
Misses ? 4049
Partials ? 0
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.
Great job, added some comments with typos and ideas.
pandas/core/strings.py
Outdated
Equivalent to :meth:`str.zfill`. | ||
Pad strings in the Series/Index by prepending '0' characters. | ||
|
||
Strings in the Series/Index are padded with prepending '0' characeters |
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.
typo in characters
pandas/core/strings.py
Outdated
Strings in the Series/Index are padded with prepending '0' characeters | ||
(i.e. on the left of the string) to reach a total string length | ||
of `width`. in the Series/Index with length greater than `width` | ||
are unchanged. |
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.
I think something went wrong with that last sentence, two spaces, not starting with a capital letter, and I think it's not that clear, a word or something is missing I guess.
pandas/core/strings.py
Outdated
are unchanged. | ||
|
||
Note: Differs from :meth:`str.zfill` which has special handling | ||
for '+'/'-' in the string. |
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 is a Notes
section in the numpy docstring convention that we can use for this:
Notes
-------
https://python-sprints.github.io/pandas/guide/pandas_docstring.html#section-6-notes
pandas/core/strings.py
Outdated
Minimum width of resulting string; additional characters will be | ||
filled with 0 | ||
Minimum length of resulting string; strings with length less | ||
than `width` be prepended with '0' characters. | ||
|
||
Returns | ||
------- | ||
filled : Series/Index of objects |
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.
you can get rid of the filled
and just leave the type (it was usual to name the return, but it was decided to not name them anymore as it doesn't add much value).
pandas/core/strings.py
Outdated
""" | ||
|
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.
no need to add this blank line here
pandas/core/strings.py
Outdated
>>> s.str.zfill(5) | ||
0 000-2 | ||
1 00005 | ||
dtype: object |
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 cool, but I think we can make it a bit more compact and clear by:
- Just creating a single
Series
(I'd get rid of one of10
or127
as they show the same user case, and I'd add aNaN
and a number (as number, not as string). - After creating the
Series
I'd show it without modification (i.e.>>> s
). This makes the result easier to compare with the original data. - We can get rid of the second example if we add the numbers in the first.
Hello @alkamid! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on July 07, 2018 at 14:20 Hours UTC |
@datapythonista thanks a lot for your valuable feedback! I've addressed all your comments, does it look better to you now? |
pandas/core/strings.py
Outdated
4 127 | ||
5 NaN | ||
dtype: object | ||
>>> s.str.zfill(5) |
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.
Looks great now. Just couple of ideas, feel free to ignore them if you prefer the way it is now.
I think it could be useful to add a short paragraph before this line explaining that the non-string values (127
and NaN
) become NaN
, and may be reemphasizing what you already have in the body of the docstring, that the values with sign (-2
and +5
) get the zeros in the left of the sign, and that 423523
keeps unchanged as it's longer than width
.
I also think that it would make things easier/faster to understand if the values look a bit less arbitrary. For example ['-1', '1', 10, np.nan, '1000']
(with a width
of 3
in this example).
pandas/core/strings.py
Outdated
""" | ||
|
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.
No need to add this blank line.
@datapythonista thanks again, suggestions incorporated into PR. Let me know what you think 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.
lgtm
…_series_str_zfill
git diff upstream/master -u -- "*.py" | flake8 --diff
Result of the Pandas sprint at PyData London 2018. Includes work by @owlas.