Description
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
>>> pd.Timestamp(str(pd.Timestamp("0001-01-01")))
Timestamp('2001-01-01 00:00:00')
>>> pd.Timestamp("0001-01-01").isoformat()
'1-01-01T00:00:00'
Issue Description
With #49737 it is now possible to create Timestamp
objects without four-digit years. The default and ISO formatted versions of them do not contain zero-padded years, which can lead to ambiguous date strings (#37071) and improper round tripping between str
and Timestamp
as illustrated in the example.
cc: @keewis
Expected Behavior
>>> import pandas as pd
>>> pd.Timestamp(str(pd.Timestamp("0001-01-01")))
Timestamp('0001-01-01 00:00:00')
>>> pd.Timestamp("0001-01-01").isoformat()
'0001-01-01T00:00:00'
Installed Versions
INSTALLED VERSIONS
commit : d3f0e9a
python : 3.8.5.final.0
python-bits : 64
OS : Darwin
OS-release : 22.2.0
Version : Darwin Kernel Version 22.2.0: Fri Nov 11 02:08:47 PST 2022; root:xnu-8792.61.2~4/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.5.0.dev0+2555.gd3f0e9a95d
numpy : 1.22.0.dev0+756.g5350aa097
pytz : 2020.1
dateutil : 2.8.2
setuptools : 49.2.0.post20200712
pip : 20.1.1
Cython : None
pytest : 5.4.3
hypothesis : 5.22.0
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.5.2
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : None
pandas_datareader: None
bs4 : 4.9.1
bottleneck : 1.4.0.dev0+78.g7c685ae
brotli :
fastparquet : None
fsspec : 0.7.4
gcsfs : None
matplotlib : 3.4.3
numba : 0.50.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.8.0.dev0+1577.2f60c33
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : 0.20.3.dev517+g17933e76
xlrd : None
zstandard : None
tzdata : None
qtpy : None
pyqt5 : None