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

[ENH]improve conditional join performance #1419

Merged
merged 9 commits into from
Dec 4, 2024

Conversation

samukweku
Copy link
Collaborator

@samukweku samukweku commented Nov 2, 2024

PR Description

Please describe the changes proposed in the pull request:

  • improve performance when using numba and join conditions are more than two

This PR relates to #1415 .

In [2]: import pandas as pd; import janitor as jn; import numpy as np; import numba

In [3]: def east_west():
   ...:     num_rows_left, num_rows_right = 5_000_000, 5_000_000
   ...:     rng = np.random.default_rng(42)
   ...:
   ...:     # Generate two separate datasets where revenue/cost are linearly related to
   ...:     # duration/time, but add some noise to the west table so that there are some
   ...:     # rows where the cost for the same or greater time will be less than the east table.
   ...:     east_dur = rng.integers(1_000, 10_000_000, num_rows_left)
   ...:     east_rev = (east_dur * 0.123).astype(np.int32)
   ...:     west_time = rng.integers(1_000, 500_000, num_rows_right)
   ...:     west_cost = west_time * 0.123
   ...:     west_cost += rng.normal(0.0, 1.0, num_rows_right)
   ...:     west_cost = west_cost.astype(np.int32)
   ...:
   ...:     east = pd.DataFrame(
   ...:         {
   ...:             "id": np.arange(0, num_rows_left),
   ...:             "dur": east_dur,
   ...:             "rev": east_rev,
   ...:             "cores": rng.integers(1, 10, num_rows_left),
   ...:         }
   ...:     )
   ...:     west = pd.DataFrame(
   ...:         {
   ...:             "t_id": np.arange(0, num_rows_right),
   ...:             "time": west_time,
   ...:             "cost": west_cost,
   ...:             "cores": rng.integers(1, 10, num_rows_right),
   ...:         }
   ...:     )
   ...:     return east, west
   ...: east,west = east_west()


# dev
%timeit eastt.conditional_join(westt, ('dur','time','<='),('rev','cost','>='), ('id','t_id', '>'), use_numba=True)
11.3 s ± 55.8 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)


# this PR
%timeit east.conditional_join(west, ('dur','time','<='),('rev','cost','>='), ('id','t_id', '>'), use_numba=True)
3.41 s ± 2.68 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

Please tag maintainers to review.

@samukweku samukweku requested review from ericmjl, thatlittleboy and a team November 2, 2024 14:05
@samukweku samukweku self-assigned this Nov 2, 2024
@samukweku samukweku linked an issue Nov 2, 2024 that may be closed by this pull request
@ericmjl
Copy link
Member

ericmjl commented Nov 2, 2024

@ericmjl
Copy link
Member

ericmjl commented Nov 22, 2024

@samukweku, I am not 100% sure of the changes here. Is there a performance improvement? If so, is there a performance comparison that you've done compared to the previous iteration?

Apologies for getting back late here on my side!

@samukweku
Copy link
Collaborator Author

@ericmjl i have updated the example to show the perf. improvement

@ericmjl
Copy link
Member

ericmjl commented Dec 1, 2024

Ah, got it! Thanks @samukweku, I trust what you've got here. Let's merge! Please also do the honors of cutting a new release! I think we should just cut releases after merging PRs, so the improvements get shipped.

@samukweku
Copy link
Collaborator Author

@ericmjl it still needs an approval 😎

Copy link

codecov bot commented Dec 1, 2024

Codecov Report

Attention: Patch coverage is 88.94231% with 46 lines in your changes missing coverage. Please review.

Project coverage is 84.67%. Comparing base (6e77fbc) to head (fad36a8).
Report is 32 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1419      +/-   ##
==========================================
- Coverage   89.07%   84.67%   -4.41%     
==========================================
  Files          87       87              
  Lines        5374     6348     +974     
==========================================
+ Hits         4787     5375     +588     
- Misses        587      973     +386     

Copy link
Member

@ericmjl ericmjl left a comment

Choose a reason for hiding this comment

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

Ack, apologies @samukweku! Approved!

@samukweku samukweku merged commit ae9b702 into dev Dec 4, 2024
4 of 6 checks passed
@samukweku samukweku deleted the 1415-enh-improve-conditional_join-performance branch December 4, 2024 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ENH] improve conditional_join performance
2 participants