-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Timestamp.strftime(): missing support for nanoseconds #29461
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
Comments
Note to self: interestingly, I just saw that Ruby's strftime has a Another note to self:
Third note to self: for the specific format I want to emit in my example above there is this working shortcut: |
Ran into this issue today. Proposed solution is to add Is the best route to fully reimplement the method? I think ideally it would look something like this def strftime(self, fmt: str) -> str:
if self.nanosecond == 0:
return super.strftime(fmt)
# else but I can't think of an elegant |
|
|
Note that for |
When parsing text into a
Timestamp
object we can specify a format string. Currently%f
is documented withSee https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.to_datetime.html, in particular the description of the
format
parameter. The note about%f
was added in this patch: #8904The fact that we can parse text using nanosecond precision is great, and here I make use of that behavior (showing two methods yielding the same result):
But when I now want to invert that process using
strftime()
then the fractional part is truncated to microsecond precision:On the one hand this is inconsistent with the meaning of
%f
while parsing. On the other hand it corresponds to what's documented in Python's stdlib documentation (which says that%f
means "Microsecond as a decimal number, zero-padded on the left.").In any case, I think it would make sense to have a format string specifier that allows us to turn the timestamp into a string with nanosecond precision.
If I am not mistaken, we otherwise have to work around the absence of that format specifier by using the
nanosecond
property:Do you agree that we should have a format specifier for that? Or do we have one, and it's just not documented?
INSTALLED VERSIONS
commit : None
python : 3.7.4.final.0
python-bits : 64
OS : Linux
OS-release : 5.3.7-200.fc30.x86_64
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 0.25.2
numpy : 1.17.3
pytz : 2019.3
dateutil : 2.8.0
pip : 19.0.3
setuptools : 40.8.0
Cython : 0.29.13
pytest : 5.2.1
hypothesis : 4.41.3
sphinx : 2.2.0
blosc : 1.8.1
feather : None
xlsxwriter : 1.2.2
lxml.etree : 4.4.1
html5lib : 1.0.1
pymysql : None
psycopg2 : None
jinja2 : 2.10.3
IPython : 7.8.0
pandas_datareader: None
bs4 : 4.8.1
bottleneck : 1.2.1
fastparquet : 0.3.2
gcsfs : None
lxml.etree : 4.4.1
matplotlib : 3.1.1
numexpr : 2.7.0
odfpy : None
openpyxl : 3.0.0
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : 0.3.5
scipy : 1.3.1
sqlalchemy : 1.3.10
tables : 3.6.0
xarray : 0.14.0
xlrd : 1.2.0
xlwt : 1.3.0
xlsxwriter : 1.2.2
The text was updated successfully, but these errors were encountered: