Skip to content

BUG: Timestamp.isoformat works incorrect on ns precision #53020

@i1oveMyse1f

Description

@i1oveMyse1f

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd ts = pd.Timestamp("2023-01-01 00:00:00") ts_1ns = ts + pd.Timedelta(nanoseconds=1) print(ts.isoformat(timespec='nanoseconds')) print(ts_1ns.isoformat(timespec='nanoseconds'))

Issue Description

If the requested precision is in nanoseconds and the timestamp has 0 microseconds, then the format is invalid and looks like the following:

2023-01-01T00:00:00.000000.000000000
2023-01-01T00:00:00.000000.000000001

Expected Behavior

2023-01-01T00:00:00.000000000
2023-01-01T00:00:00.000000001

Installed Versions

/opt/homebrew/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/_distutils_hack/__init__.py:33: UserWarning: Setuptools is replacing distutils. warnings.warn("Setuptools is replacing distutils.") INSTALLED VERSIONS ------------------ commit : 37ea63d540fd27274cad6585082c91b1283f963d python : 3.11.2.final.0 python-bits : 64 OS : Darwin OS-release : 22.4.0 Version : Darwin Kernel Version 22.4.0: Mon Mar 6 20:59:28 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T6000 machine : arm64 processor : arm byteorder : little LC_ALL : None LANG : ru_RU.UTF-8 LOCALE : ru_RU.UTF-8 pandas : 2.0.1 numpy : 1.24.2 pytz : 2023.3 dateutil : 2.8.2 setuptools : 65.6.3 pip : 23.1 Cython : None pytest : None hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : None pymysql : None psycopg2 : None jinja2 : 3.1.2 IPython : 8.12.0 pandas_datareader: None bs4 : 4.12.2 bottleneck : None brotli : None fastparquet : None fsspec : None gcsfs : None matplotlib : 3.7.1 numba : None numexpr : None odfpy : None openpyxl : 3.1.2 pandas_gbq : None pyarrow : None pyreadstat : None pyxlsb : None s3fs : None scipy : 1.10.1 snappy : None sqlalchemy : None tables : None tabulate : None xarray : None xlrd : None zstandard : None tzdata : 2023.3 qtpy : None pyqt5 : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugTimestamppd.Timestamp and associated methods

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions