-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: GH29461 Strftime #34668
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
BUG: GH29461 Strftime #34668
Conversation
… compatability with datetime.strptime()
result += f'.{self.microsecond:06d}' | ||
|
||
return result | ||
fmt = '%H:%M:%S' |
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.
does this change any of the benchmarks?
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.
Looks like we suffer a penalty for the additional super()
function call in strftime()
, and then there's an additional performance impact when we actually need to process nanoseconds.
before after ratio
[6efb0b20] [0c4ef36f]
<master> <strftime>
+ 3.61±0.1μs 4.40±0.2μs 1.22 tslibs.timestamp.TimestampStrftimeMethod.time_strftime('%Y-%m-%d %H:%M:%S.%f')
+ 3.29±0.1μs 3.68±0.05μs 1.12 tslibs.timestamp.TimestampStrftimeMethod.time_strftime('%Y-%m-%d %H:%M:%S')
+ 8.91±0.2μs 9.90±0.4μs 1.11 tslibs.timestamp.TimestampProperties.time_month_name(None, None)
- 409±20ns 308±10ns 0.75 tslibs.timestamp.TimestampProperties.time_days_in_month(<UTC>, 'B')
pandas/_libs/tslibs/timestamps.pyx
Outdated
""" | ||
if '%f' in format and self.nanosecond: | ||
replacement = f'{self.microsecond * 1000 + self.nanosecond:09d}' | ||
format = re.sub('%f', replacement, format) |
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.
can you use string replacement rather than re? doesn't this change perf?
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.
Good call. Tested both and string replace is WAY more performant.
@matteosantama can you merge master and fix the conflicts? |
can u merge master, and show benchmarks again; ping on green |
@jreback All checks passing. ASV output is a little confusing. Not entirely sure why so many tests were affected.
|
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.
Looks like a merge conflict - can you move note to 1.2?
str | ||
String representation of Timestamp | ||
""" | ||
if self.nanosecond and '%f' in format: |
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.
Is there a reason for this check and the one on L649? Can there just be one check done here?
@@ -915,6 +915,7 @@ Datetimelike | |||
- Bug in :meth:`DatetimeIndex.intersection` and :meth:`TimedeltaIndex.intersection` with results not having the correct ``name`` attribute (:issue:`33904`) | |||
- Bug in :meth:`DatetimeArray.__setitem__`, :meth:`TimedeltaArray.__setitem__`, :meth:`PeriodArray.__setitem__` incorrectly allowing values with ``int64`` dtype to be silently cast (:issue:`33717`) | |||
- Bug in subtracting :class:`TimedeltaIndex` from :class:`Period` incorrectly raising ``TypeError`` in some cases where it should succeed and ``IncompatibleFrequency`` in some cases where it should raise ``TypeError`` (:issue:`33883`) | |||
- Bug in :meth:`Timestamp.strftime` did not display full nanosecond precision (:issue:`29461`) |
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.
move to 1.2
Hi @matteosantama - is this still active? If so, could you address Jeff's and Will's comments please? |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff
Closed the other PR while I sorted some things out.