Skip to content

PERF: increase performance of str_split when returning a frame #10090

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

Merged
merged 1 commit into from
Jun 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.16.2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Performance Improvements
~~~~~~~~~~~~~~~~~~~~~~~~

- Improved ``Series.resample`` performance with dtype=datetime64[ns] (:issue:`7754`)
- Increase performance of ``str.split`` when ``expand=True`` (:issue:`10081`)

.. _whatsnew_0162.bug_fixes:

Expand Down
8 changes: 6 additions & 2 deletions pandas/core/strings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np

from pandas.compat import zip
from pandas.core.common import isnull, _values_from_object, is_bool_dtype
from pandas.core.common import isnull, _values_from_object, is_bool_dtype, is_list_like
import pandas.compat as compat
from pandas.util.decorators import Appender, deprecate_kwarg
import re
Expand Down Expand Up @@ -1090,7 +1090,11 @@ def _wrap_result_expand(self, result, expand=False):
else:
index = self.series.index
if expand:
cons_row = self.series._constructor
def cons_row(x):
if is_list_like(x):
return x
else:
return [ x ]
cons = self.series._constructor_expanddim
data = [cons_row(x) for x in result]
return cons(data, index=index)
Expand Down
1 change: 1 addition & 0 deletions vb_suite/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def make_series(letters, strlen, size):
strings_match = Benchmark("many.str.match(r'mat..this')", setup)
strings_extract = Benchmark("many.str.extract(r'(\w*)matchthis(\w*)')", setup)
strings_join_split = Benchmark("many.str.join(r'--').str.split('--')", setup)
strings_join_split_expand = Benchmark("many.str.join(r'--').str.split('--',expand=True)", setup)
strings_len = Benchmark("many.str.len()", setup)
strings_findall = Benchmark("many.str.findall(r'[A-Z]+')", setup)
strings_pad = Benchmark("many.str.pad(100, side='both')", setup)
Expand Down