8000 ENH: #9847, adding a "same" and "expand" param to StringMethods.split() by sreejata · Pull Request #9870 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

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

Closed
wants to merge 7 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Cleaning up
  • Loading branch information
sreejata authored and sreejata committed Apr 13, 2015
commit 4ede22a155ae196188c24e5d816e399b2894abf7
4 changes: 2 additions & 2 deletions pandas/core/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ def str_split(arr, pat=None, n=None, return_type='series'):

Copy link
Contributor

Choose a reason for hiding this comment

The 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 dict to organize the mapping from old to new arg names, at the beginning of the function, something like:

arg_map = {'series': 'same', 'index': 'same', 'frame': 'expand'}
if return_type in arg_map:
    warnings.warn("return_type='%s' is deprecated, please use '%s' instead" % (return_type, arg_map[return_type]), FutureWarning)
    return_type = arg_map[return_type]

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.

Copy link
Author

Choose a reason for hiding this comment

The 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', 'same', 'expand'):
raise ValueError("return_type must be {'series', 'index', 'frame', 'same', 'expand'}")
Copy link
Member

Choose a reason for hiding this comment

The 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):
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:
Expand All @@ -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' or return_type == 'expand':
if return_type in ('frame', 'expand'):
res = DataFrame((Series(x) for x in _na_map(f, arr)), index=arr.index)
else:
res = _na_map(f, arr)
Expand Down
0