-
-
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
Changes from all commits
12d0b4d
02c4a85
7e3256b
f00e48a
a90f928
26a920c
3a529ac
d0124aa
0c0aaf2
abdbe4e
97ae6b3
1132aba
0e42026
ab0c9d4
532b19c
88fba5e
2ac690c
3b533c9
f6ba1c9
07b27e2
4b57c4f
d72222a
e920d20
34db469
fbe286e
54d30eb
90629c5
821dfbb
16b0f9f
b8565f2
6866a3d
3806567
a4ddcbb
7fe0a5e
ce9ef3d
7b69abb
858b3fb
e7b8525
6a2f3d2
d62ff1d
cbb735e
0c4ef36
62c1126
4468168
88c7e26
4d433f9
b0de2c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -645,14 +645,10 @@ cdef class _Timestamp(ABCTimestamp): | |
|
||
@property | ||
def _time_repr(self) -> str: | ||
result = f'{self.hour:02d}:{self.minute:02d}:{self.second:02d}' | ||
|
||
if self.nanosecond != 0: | ||
result += f'.{self.nanosecond + 1000 * self.microsecond:09d}' | ||
elif self.microsecond != 0: | ||
result += f'.{self.microsecond:06d}' | ||
|
||
return result | ||
fmt = '%H:%M:%S' | ||
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 this change any of the benchmarks? 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. Looks like we suffer a penalty for the additional
|
||
if self.microsecond or self.nanosecond: | ||
fmt = '%H:%M:%S.%f' | ||
return self.strftime(fmt) | ||
|
||
@property | ||
def _short_repr(self) -> str: | ||
|
@@ -1473,6 +1469,28 @@ default 'raise' | |
self.nanosecond / 3600.0 / 1e+9 | ||
) / 24.0) | ||
|
||
def strftime(self, format: str) -> str: | ||
""" | ||
Constructs datetime style `format` string from Timestamp. | ||
|
||
See `datetime <https://docs.python.org/3/library/datetime\ | ||
.html#strftime-and-strptime-format-codes>`_ module for all available directives. | ||
|
||
Parameters | ||
---------- | ||
format : str | ||
String of formatting directives | ||
|
||
Returns | ||
------- | ||
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 commentThe 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? |
||
replacement = f'{self.microsecond * 1000 + self.nanosecond:09d}' | ||
format = format.replace('%f', replacement) | ||
return super().strftime(format) | ||
|
||
|
||
# Aliases | ||
Timestamp.weekofyear = Timestamp.week | ||
|
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