-
-
Notifications
You must be signed in to change notification settings - Fork 18.8k
ENH: #9847, adding a "same" and "expand" param to StringMethods.split() #9870
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
Changes from 1 commit
38f96dd
4ede22a
df4d0ee
c8f14dd
612e0c0
d2c57da
a5e1084
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
….split() return value
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -632,9 +632,9 @@ def str_split(arr, pat=None, n=None, return_type='series'): | |
pat : string, default None | ||
String or regular expression to split on. If None, splits on whitespace | ||
n : int, default None (all) | ||
return_type : {'series', 'index', 'frame'}, default 'series' | ||
If frame, returns a DataFrame (elements are strings) | ||
If series or index, returns the same type as the original object | ||
return_type : {'series', 'index', 'frame', 'same', 'expand'}, default 'series' | ||
If frame or expand, returns a DataFrame (elements are strings) | ||
If series, index or same, returns the same type as the original object | ||
(elements are lists of strings). | ||
|
||
Notes | ||
|
@@ -649,9 +649,9 @@ def str_split(arr, pat=None, n=None, return_type='series'): | |
from pandas.core.frame import DataFrame | ||
from pandas.core.index import Index | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a minor point but it might be good idea to use a
this way the rest of the code doesn't have to contain references to the old names, making it easier to remove the deprecation stuff later. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be updated to use expand=True/False or keep as same/expand? |
||
if return_type not in ('series', 'index', 'frame'): | ||
raise ValueError("return_type must be {'series', 'index', 'frame'}") | ||
if return_type == 'frame' and isinstance(arr, Index): | ||
if return_type not in ('series', 'index', 'frame', 'same', 'expand'): | ||
raise ValueError("return_type must be {'series', 'index', 'frame', 'same', 'expand'}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also, here I would only mention 'same' and 'expand' |
||
if return_type in ['frame', 'expand'] and isinstance(arr, Index): | ||
raise ValueError("return_type='frame' is not supported for string " | ||
"methods on Index") | ||
if pat is None: | ||
|
@@ -668,7 +668,7 @@ def str_split(arr, pat=None, n=None, return_type='series'): | |
n = 0 | ||
regex = re.compile(pat) | ||
f = lambda x: regex.split(x, maxsplit=n) | ||
if return_type == 'frame': | ||
if return_type == 'frame' or return_type == 'expand': | ||
res = DataFrame((Series(x) for x in _na_map(f, arr)), index=arr.index) | ||
else: | ||
res = _na_map(f, arr) | ||
|
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 would only mention 'same' here (as you did for 'frame')