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

feat: dt.truncate supports broadcasting lhs #15768

Merged
merged 1 commit into from
Apr 19, 2024

Conversation

reswqa
Copy link
Collaborator

@reswqa reswqa commented Apr 19, 2024

Probably not much, but this should also improve some performance as the duration parsing cache.

Closes #15743.

@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars labels Apr 19, 2024
@MarcoGorelli
Copy link
Collaborator

thanks for doing this! is sqrt(n) a good size to use in general? should that be used in #15736 ?

Copy link

codecov bot commented Apr 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.35%. Comparing base (0c2783a) to head (8958d12).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #15768   +/-   ##
=======================================
  Coverage   81.35%   81.35%           
=======================================
  Files        1379     1379           
  Lines      176619   176683   +64     
  Branches     2544     2542    -2     
=======================================
+ Hits       143686   143748   +62     
- Misses      32449    32453    +4     
+ Partials      484      482    -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

codspeed-hq bot commented Apr 19, 2024

CodSpeed Performance Report

Merging #15768 will not alter performance

Comparing reswqa:truncate_broadcast_left (8958d12) with main (0423fa3)

Summary

✅ 22 untouched benchmarks

@reswqa
Copy link
Collaborator Author

reswqa commented Apr 19, 2024

Before #15736, I'm not aware that there would be such a performance penalty if the size is not good.

thanks for doing this! is sqrt(n) a good size to use in general? should that be used in #15736 ?

To be honest, I'm not totally sure as I didn't do the benchmark for the cache size, just the keep it the same as we use elsewhere(e.g. extract_all_many).

But for truncate, though, it shouldn't need to be very large IMO. I have a feeling that durations usually don't have too many unique values (i.e. cache hit rate might be high).

@reswqa reswqa marked this pull request as ready for review April 19, 2024 12:18
Copy link
Collaborator

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

thanks for fixing this and for adding the cache!

@ritchie46 ritchie46 merged commit 944e089 into pola-rs:main Apr 19, 2024
27 checks passed
@MarcoGorelli
Copy link
Collaborator

I think there may have been a performance impact from this for when every isn't an expression (but also a perf improvement when it is)

e.g.:

import timeit
import numpy as np

setup = """

import pandas as pd
import polars as pl
import numpy as np

rng = np.random.default_rng(1)
s = pl.Series(rng.integers(-1_000_000, 1_000_000, size=1_000_000)).cast(pl.Datetime)
df = pl.DataFrame({'dt': s})
df = df.with_columns(every=pl.Series(['10s']*(len(s)//2) + ['100s']*(len(s)//2)))
"""

results = np.array(timeit.Timer(
    stmt="df.select(pl.col('dt').dt.truncate('10s'))",
    setup=setup,
    )
    .repeat(7, 3)
)/3
print(f"min: {min(results)}")
print(f"max: {max(results)}")
print(f"{np.mean(results)} +/- {np.std(results)/np.sqrt(len(results))}")

results = np.array(timeit.Timer(
    stmt="df.select(pl.col('dt').dt.truncate(pl.col('every')))",
    setup=setup,
    )
    .repeat(7, 3)
)/3
print(f"min: {min(results)}")
print(f"max: {max(results)}")
print(f"{np.mean(results)} +/- {np.std(results)/np.sqrt(len(results))}")
(.venv) marcogorelli@DESKTOP-U8OKFP3:~/scratch$

On 0.20.21, minimum timings are:

  • 0.01931395099988246
  • 0.04977888566645561

On 0.20.22, they are:

  • 0.040716169999844475
  • 0.050329010666852504

So, I think the separate paths need to be restored?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

truncate does not correctly broadcast scalar vs expression
3 participants