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("2023-01-01").to_datetime64().dtype
# Pandas 1.5.3 >>> dtype('<M8[ns]')
# Pandas 2.0.0 >>> dtype('<M8[s]')
Issue Description
With pandas 2.0.0 pd.Timestamp("%Y-%m-%d").to_datetime64()
returns a numpy datetime with a resolution of a second [s], instead of [ns]. It dynamically upgrades the precision depending on digits given.
For example:
pd.Timestamp("2023-01-01").to_datetime64().dtype
--> dtype('<M8[s]')
pd.Timestamp("2023-01-01 00:00:00.001").to_datetime64().dtype
--> dtype('<M8[ms]')
pd.Timestamp("2023-01-01 00:00:00.000001").to_datetime64().dtype
--> dtype('<M8[us]')
pd.Timestamp("2023-01-01 00:00:00.000000001").to_datetime().dtype
--> dtype('<M8[ns]')
Whereas pandas 1.5.3 will always use dtype('<M8[ns]')
I'm not 100% sure if this is a bug or a feature of pandas 2.0.0 but it makes migration to 2.x quite painful for those who work a lot with plain int timestamps. Typically, affected applications don't crash and just silently carry on with the wrong precision so this change will potentially lead to many hard to find bugs.
Expected Behavior
I expect that pandas 2.0.0 also defaults to dtype('<M8[ns]')
Installed Versions
INSTALLED VERSIONS
commit : 2e218d1
python : 3.11.2.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.22000
machine : AMD64
processor : Intel64 Family 6 Model 154 Stepping 3, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1252
pandas : 1.5.3
numpy : 1.24.2
pytz : 2023.3
dateutil : 2.8.2
setuptools : 65.5.0
pip : 22.3.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 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None