-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Conversation
@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 |
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.
Hypothesis-testing the hell out of this as you can't be too careful here 😇
.dt.weekday
20x faster.dt.weekday
20x faster
Awesome. Have I already mentioned chrono is slow? :D |
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
TL;DR: use maths instead of Chrono