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: Make .dt.weekday 20x faster #17992

Merged
merged 1 commit into from
Aug 1, 2024
Merged

Conversation

MarcoGorelli
Copy link
Collaborator

@MarcoGorelli MarcoGorelli commented Aug 1, 2024

TL;DR: use maths instead of Chrono

Comment on lines +2287 to +2311
@given(
value=st.datetimes(min_value=datetime(1800, 1, 1), max_value=datetime(2100, 1, 1)),
time_zone=st.sampled_from(["UTC", "Asia/Kathmandu", "Europe/Amsterdam", None]),
time_unit=st.sampled_from(["ms", "us", "ns"]),
)
def test_weekday_vs_stdlib_datetime(
value: datetime, time_zone: str, time_unit: TimeUnit
) -> None:
result = (
pl.Series([value], dtype=pl.Datetime(time_unit))
.dt.replace_time_zone(time_zone)
.dt.weekday()
.item()
)
expected = value.isoweekday()
assert result == expected


@given(
value=st.dates(),
)
def test_weekday_vs_stdlib_date(value: date) -> None:
result = pl.Series([value]).dt.weekday().item()
expected = value.isoweekday()
assert result == expected
Copy link
Collaborator Author

@MarcoGorelli MarcoGorelli Aug 1, 2024

Choose a reason for hiding this comment

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

Hypothesis-testing the hell out of this as you can't be too careful here 😇

@MarcoGorelli MarcoGorelli changed the title perf: make .dt.weekday 20x faster perf: Make .dt.weekday 20x faster Aug 1, 2024
@github-actions github-actions bot added performance Performance issues or improvements python Related to Python Polars rust Related to Rust Polars and removed title needs formatting labels Aug 1, 2024
@ritchie46
Copy link
Member

use maths instead of Chrono

Awesome. Have I already mentioned chrono is slow? :D

Copy link

codecov bot commented Aug 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.49%. Comparing base (5134051) to head (ec5cb08).
Report is 19 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #17992      +/-   ##
==========================================
+ Coverage   80.40%   80.49%   +0.08%     
==========================================
  Files        1494     1496       +2     
  Lines      196480   196646     +166     
  Branches     2817     2817              
==========================================
+ Hits       157982   158292     +310     
+ Misses      37978    37833     -145     
- Partials      520      521       +1     

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

@MarcoGorelli MarcoGorelli marked this pull request as ready for review August 1, 2024 11:42
@ritchie46 ritchie46 merged commit 316d621 into pola-rs:main Aug 1, 2024
28 of 29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Performance issues or improvements python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants