-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
ENH: Implement core/strings/wrap method #6705
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
Conversation
This patch implements the str_wrap function within core/strings. The implementation follows the behavior of R's stringr library. When a string is 'wrap'ped, the return value will be a paragraph with lines of max(word length, width) length.
can you show an example in the top fo the PR of using this. Also need to add to the documentation in also add to |
Couldn't this leverage the |
…R's stringr library defaults and semantics (width being exclusive).
Expanded docstring with description of major optional parameters and added an example.
I've changed the implementation to use the I've also added a mention of
|
@@ -710,20 +711,64 @@ def str_rstrip(arr, to_strip=None): | |||
return _na_map(lambda x: x.rstrip(to_strip), arr) | |||
|
|||
|
|||
def str_wrap(arr, width=80): | |||
def str_wrap(arr, **kwargs): |
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.
should all of the arguments and their defaults be here? is their a reason you did it this other way?
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.
Since str_wrap
is a wrapper around textwrap.TextWrapper.wrap
, I did not want to restrict the interface to a subset of the options available. (There have been at least three parameters added to textwrap.TextWrapper
from python 2.6 to 3.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.
hmm...that makes sense, the only issue then is the doc string.... @jorisvandenbossche any idea?
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.
@jeffreystarr does the doc-string work?
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 it is OK now, with the docstring explaining the parameters. It's only the signature now that does not include all those.
But what is the reason not including the keyword arguments and its default values in the signature but instead in a dict in the function?
library str_wrap function. Unless overwritten using kwargs, the instance has expand_tabs=False, | ||
replace_whitespace=True, drop_whitespace=True, break_long_words=False, and | ||
break_on_hyphens=False. Since R's stringr str_wrap treats the line width as an exclusive | ||
value, the instance is configured with width=user-supplied width - 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.
Shouldn't we rather go with python's default value instead of changing the user input? And then putting a note explaining the difference with R?
… (thus matching textwrap module)
@@ -195,6 +195,7 @@ Improvements to existing features | |||
- Performance improvement when converting ``DatetimeIndex`` to floating ordinals | |||
using ``DatetimeConverter`` (:issue:`6636`) | |||
- Performance improvement for ``DataFrame.shift`` (:issue: `5609`) | |||
- Arrays of strings can be wrapped to a specified width (str.wrap) |
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 the refernce to this PR number
@jeffreystarr pls rebase this |
@jeffreystarr - I'd also like to make width a positional argument, which lets you do something like: As an aside, this previously was just NotImplemented right? So there's no issue with forcing width to be passed? |
You are correct - it was previously NotImplemented. There is no impact to On Sat, Apr 5, 2014 at 7:41 PM, Jeff Tratner [email protected]:
|
@jeffreystarr - great, then if it's okay with you, I'd suggest changing |
@jeffreystarr this looks good can you can squash down to 1 commit would be great |
width : int | ||
Maximum line-width | ||
expand_tabs: bool, optional |
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 should be a space before the :
(like for width
above)
Add test case for iterator data argument Move the type check up to where other checks are performed Use asserRaisesRegexp for more specific checking Add fix to the release notes
hmm...looks like you somehow rebase to a different head
should do the trick if it doesn't, then:
then this 'starts' you over you can then
and it will erase this and replace with your new |
small note on the advice of @jreback: be sure that
|
This patch implements the str_wrap function within core/strings. The implementation follows the behavior of R's stringr library. When a string is 'wrap'ped, the return value will be a paragraph with lines of max(word length, width) length.
…R's stringr library defaults and semantics (width being exclusive).
Expanded docstring with description of major optional parameters and added an example.
… (thus matching textwrap module)
…an the direct str_wrap form.
…o str_wrap Conflicts: doc/source/release.rst doc/source/v0.14.0.txt
closing in favor of #6999 |
This patch implements the str_wrap function within core/strings. The implementation follows
the behavior of R's stringr library. When a string is 'wrap'ped, the return value will be a
paragraph with lines of max(word length, width) length.
Example: