-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
PERF: Add if branch for empty sep in str.cat #26605
Conversation
pandas/core/strings.py
Outdated
@@ -48,6 +48,8 @@ def cat_core(list_of_columns, sep): | |||
nd.array | |||
The concatenation of list_of_columns with sep | |||
""" | |||
if sep == '': |
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 show the benchmarks which change here?
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.
See the middle block of this comment
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.
that was 8 months ago
pls show a new one
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.
This is a clear and unambiguous reduction in necessary computation, I fail to see how an ASV run is necessary (beyond what was done already, and especially since that code hasn't changed since then).
Maybe I'll get around to it in the next few weeks.
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 don't consider this totally unambiguous - is this only applicable to extremely wide data frames? Benchmarks and context would be very useful
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.
this adds complexity. unless this is like 2x faster would close this.
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.
@WillAyd: I don't consider this totally unambiguous - is this only applicable to extremely wide data frames? Benchmarks and context would be very useful
Maybe the issue is not as apparent as I thought. Assuming a list_of_columns=[s, t, u, v]
where (s, t, u, v
are Series), then cat_core
takes that list and interleaves sep
to arrive at [s, sep, t, sep, u, sep, v]
and pushes the whole thing into np.sum
.
However, if the sep=''
, there is effectively nothing to add, and we're just uselessly wasting cycles to interleave (and then add) an empty sep
.
@jreback: this adds complexity. unless this is like 2x faster would close this.
.str.cat
has about 200LoC (not counting docstrings). Having 2 lines (1% of total) required to achieve 100% speedup sounds like an impossible standard for any perf-related change.
Based on the last runs in October (will try to do new ones as I said), I expect a 20-30% speedup for the (very common) case that sep=''
. That should be more than enough to justify two trivial lines of code, IMO.
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.
Based on the last runs in October (will try to do new ones as I said), I expect a 20-30% speedup for the (very common) case that sep=''. That should be more than enough to justify two trivial lines of code, IMO.
if that's true, then great. pls show benchmarks.
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.
Running the ASV is on my todo-list...
Codecov Report
@@ Coverage Diff @@
## master #26605 +/- ##
==========================================
- Coverage 93.02% 91.84% -1.18%
==========================================
Files 182 174 -8
Lines 50253 50709 +456
==========================================
- Hits 46746 46576 -170
- Misses 3507 4133 +626
Continue to review full report at Codecov.
|
Finally got around to running the ASVs:
Note that this is for N=10000: pandas/asv_bench/benchmarks/strings.py Line 116 in 0fd888c
I believe the gains would be even better for larger arrays. |
k thanks |
Follow-up to #23167, resp dropping py2. The branch I'm readding here had to be deleted originally to pass some python2 bytes-tests. In case there is no separator, we can avoid all the list-ops and speed up cat_core by a fair bit.