-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
PERF: Some faster date/time string formatting #46759
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
Merged
jreback
merged 40 commits into
pandas-dev:main
from
smarie:feature/44764_strftime_perf_datetimes
Jul 1, 2022
Merged
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
01b9667
Performance improvement in :class:`BusinessHour`, ``repr`` is now 4 t…
139f229
For the record: switching the repr in TimeDelta to old-style formatting
75e8fd6
added comment
0beed46
Minor: comment on speed
cdffff8
added two comments for maintenance, about speed
903d08c
Performance improvement in :class:`DatetimeArray` and :class:`Datetim…
f6e4e5a
A few comments related to time formatting
9851b36
Performance improvement in :meth:`Series.to_excel` and :meth:`DataFra…
d302fe1
Added maintenance comments
54f51f0
Performance improvement in `Series.to_sql` and `DataFrame.to_sql` (`S…
378e7f4
Merge branch 'main' of https://github.com/pandas-dev/pandas into feat…
6d60a04
Revert "For the record: switching the repr in TimeDelta to old-style …
705471f
Updated what's new wrt code review
a5203ff
Fixed what's new error
1c00b3a
Simplified sqlite adapter for time to handle both with and without ti…
2fde239
Fixed test
cb8b6d2
Update pandas/_libs/tslibs/offsets.pyx
smarie 1e49c05
Fixed Flake8 warning
405a5f6
Added ASVs for strftime related perf
76035d5
Removed all other offsets from the ASV as they are not relevant
a788135
black and isort
3f3725e
Added default format for dates
5eee079
FixedImproved ASVs
165aefa
Merge branch 'main' of https://github.com/pandas-dev/pandas into feat…
7fcb31f
Code review: removed __main__ in asv bench
abc0032
code review: whatsnew
956c297
Code review: added asserts to ensure basic_format and basic_format_da…
ce6e4ac
Code review: inline comment style
b54196f
Attempt to improve SQL ASV (not tested)
8df827c
Fixed SQL ASV Bench.
898c047
Black
1b991e5
As per code review: moved assert outside of for loop
0a6e8fb
Merge branch 'main' of https://github.com/pandas-dev/pandas into feat…
3e42fd4
As per code review: removed 2 useless variables and edited a comment
fc078b9
Fixed wrong merge
e410b31
Merge branch 'main' of https://github.com/pandas-dev/pandas into feat…
32b03a8
Aligned the basic format day with new `pandas_datetime_to_datetimestr…
6561e77
Merge branch 'main' of https://github.com/pandas-dev/pandas into feat…
7adff9b
Removed useless line
d104bb4
Merge branch 'main' of https://github.com/pandas-dev/pandas into feat…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import numpy as np | ||
|
||
import pandas as pd | ||
from pandas import offsets | ||
|
||
|
||
class DatetimeStrftime: | ||
timeout = 1500 | ||
params = [1000, 10000] | ||
param_names = ["obs"] | ||
|
||
def setup(self, obs): | ||
d = "2018-11-29" | ||
dt = "2018-11-26 11:18:27.0" | ||
self.data = pd.DataFrame( | ||
{ | ||
"dt": [np.datetime64(dt)] * obs, | ||
"d": [np.datetime64(d)] * obs, | ||
"r": [np.random.uniform()] * obs, | ||
} | ||
) | ||
|
||
def time_frame_date_to_str(self, obs): | ||
self.data["d"].astype(str) | ||
|
||
def time_frame_date_formatting_default(self, obs): | ||
self.data["d"].dt.strftime(date_format="%Y-%m-%d") | ||
|
||
def time_frame_date_formatting_custom(self, obs): | ||
self.data["d"].dt.strftime(date_format="%Y---%m---%d") | ||
|
||
def time_frame_datetime_to_str(self, obs): | ||
self.data["dt"].astype(str) | ||
|
||
def time_frame_datetime_formatting_default_date_only(self, obs): | ||
self.data["dt"].dt.strftime(date_format="%Y-%m-%d") | ||
|
||
def time_frame_datetime_formatting_default(self, obs): | ||
self.data["dt"].dt.strftime(date_format="%Y-%m-%d %H:%M:%S") | ||
|
||
def time_frame_datetime_formatting_default_with_float(self, obs): | ||
self.data["dt"].dt.strftime(date_format="%Y-%m-%d %H:%M:%S.%f") | ||
|
||
def time_frame_datetime_formatting_custom(self, obs): | ||
self.data["dt"].dt.strftime(date_format="%Y-%m-%d --- %H:%M:%S") | ||
|
||
|
||
class BusinessHourStrftime: | ||
timeout = 1500 | ||
params = [1000, 10000] | ||
param_names = ["obs"] | ||
|
||
def setup(self, obs): | ||
self.data = pd.DataFrame( | ||
{ | ||
"off": [offsets.BusinessHour()] * obs, | ||
} | ||
) | ||
|
||
def time_frame_offset_str(self, obs): | ||
self.data["off"].apply(str) | ||
|
||
def time_frame_offset_repr(self, obs): | ||
self.data["off"].apply(repr) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -792,6 +792,10 @@ Performance improvements | |
- Performance improvement in :func:`read_excel` when ``nrows`` argument provided (:issue:`32727`) | ||
- Performance improvement in :meth:`.Styler.to_excel` when applying repeated CSS formats (:issue:`47371`) | ||
- Performance improvement in :meth:`MultiIndex.is_monotonic_increasing` (:issue:`47458`) | ||
- Performance improvement in :class:`BusinessHour` ``str`` and ``repr`` (:issue:`44764`) | ||
- Performance improvement in datetime arrays string formatting when one of the default strftime formats ``"%Y-%m-%d %H:%M:%S"`` or ``"%Y-%m-%d %H:%M:%S.%f"`` is used. (:issue:`44764`) | ||
- Performance improvement in :meth:`Series.to_sql` and :meth:`DataFrame.to_sql` (:class:`SQLiteTable`) when processing time arrays. (:issue:`44764`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does "time" arrays refer to datetime64 dtype? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, rather |
||
- | ||
|
||
.. --------------------------------------------------------------------------- | ||
.. _whatsnew_150.bug_fixes: | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
sorry for the late review; these benchmarks don't belong in the tslibs directory (unless you can re-write them to not depend on anything outside of tslibs). can you do a follow-up to move them?
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.
yes sure, do you think that moving them one folder up would be enough ?
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.
that would do it, yes. thanks
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.
Done in #47665 . Let's wait for a successful build just in case..