Skip to content
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: avoid creating many Series in apply_standard #34909

Merged
merged 9 commits into from
Jun 25, 2020

Conversation

jbrockmendel
Copy link
Member

@jbrockmendel jbrockmendel commented Jun 20, 2020

  • closes #xxxx
  • tests added / passed
  • passes black pandas
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

This avoids going through perennial-problem-causing libreduction code (xref #34014, #34080) and instead does the same trick in python-space by re-assigning block.values instead of creating new Series objects.

If we avoid libreduction but dont do this optimization, the most-affected asv is time_apply_ref_by_name that clocks in at 6.92x slower. This achieves parity on that asv.

ATM I'm still getting 4 test failures locally, need to troubleshoot. Update: passing

mgr = ser._mgr
blk = mgr.blocks[0]

for (arr, name) in zip(values, self.index):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you push this to an internals method instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im looking at that now. the other place where this pattern could be really useful is in groupby.ops, but its tougher there

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure also exposing an api for this would be ok as well (eg another internals method)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im still troubleshooting the groupby.ops usage, would like to punt on making this an internals method for the time being

@jreback jreback added Apply Apply, Aggregate, Transform, Map Performance Memory or execution speed performance labels Jun 23, 2020
@jreback
Copy link
Contributor

jreback commented Jun 23, 2020

does this fix #34506 ?

@jbrockmendel
Copy link
Member Author

does this fix #34506 ?

The example from the OP there was fixed by #34913, but i still need to double-check the general case and add a test.

@jbrockmendel
Copy link
Member Author

The groupby.ops analogue of this is continuing to be a PITA, so im exploring other avenues there (xred #34982). This should be good to go though, and as a follow-up we can rip out libreduction.Reducer.

@jreback jreback added this to the 1.1 milestone Jun 25, 2020
@jreback jreback merged commit 91802a9 into pandas-dev:master Jun 25, 2020
@jreback
Copy link
Contributor

jreback commented Jun 25, 2020

thanks, yeah incremental refactors are good.

@jbrockmendel jbrockmendel deleted the perf-apply_standard branch June 25, 2020 23:15
fangchenli pushed a commit to fangchenli/pandas that referenced this pull request Jun 27, 2020
@jorisvandenbossche
Copy link
Member

This commit caused some regressions, eg https://pandas.pydata.org/speed/pandas/#frame_methods.Apply.time_apply_np_mean,
https://pandas.pydata.org/speed/pandas/#frame_methods.Apply.time_apply_ref_by_name?x-axis-scale=date

Was that expected? (above you mention "achieves parity on that asv.")

@jorisvandenbossche
Copy link
Member

Ah, I suppose this is just fixed by #35166

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Apply Apply, Aggregate, Transform, Map Performance Memory or execution speed performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants