BUG: datetime64 column has incorrect unit when created with pd.Timestamp #60773
Closed
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
ts_list = ["2021-01-01 00:00:00", "2021-01-01 00:00:01", "2021-01-01 00:00:02"]
df = pd.DataFrame(
{
"ts1": [pd.Timestamp(ts) for ts in ts_list],
"ts2": pd.to_datetime(ts_list),
}
).assign(
ts3=pd.Timestamp(ts_list[0]),
ts4=pd.Timestamp(ts_list[0], unit="ns"),
ts5=pd.to_datetime(ts_list[0]),
)
Issue Description
Then
df.dtypes
gives
ts1 datetime64[ns]
ts2 datetime64[ns]
ts3 datetime64[s]
ts4 datetime64[s]
ts5 datetime64[ns]
dtype: object
Expected Behavior
I would expect the above to output
ts1 datetime64[ns]
ts2 datetime64[ns]
ts3 datetime64[ns]
ts4 datetime64[ns]
ts5 datetime64[ns]
dtype: object
Installed Versions
INSTALLED VERSIONS
------------------
commit : 0691c5cf90477d3503834d983f69350f250a6ff7
python : 3.11.10
python-bits : 64
OS : Darwin
OS-release : 24.2.0
Version : Darwin Kernel Version 24.2.0: Fri Dec 6 19:02:41 PST 2024; root:xnu-11215.61.5~2/RELEASE_ARM64_T6030
machine : arm64
processor : arm
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 2.2.3
numpy : 1.24.4
pytz : 2024.2
dateutil : 2.9.0.post0
pip : 24.2
Cython : 3.0.11
sphinx : None
IPython : 8.31.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.3
blosc : None
bottleneck : 1.3.7
dataframe-api-compat : None
fastparquet : None
fsspec : 2023.12.2
html5lib : 1.1
hypothesis : 6.123.17
gcsfs : None
jinja2 : 3.1.5
lxml.etree : 5.3.0
matplotlib : 3.8.4
numba : 0.60.0
numexpr : 2.10.2
odfpy : None
openpyxl : 3.1.5
pandas_gbq : None
psycopg2 : 2.9.10
pymysql : None
pyarrow : 16.1.0
pyreadstat : None
pytest : 7.4.4
python-calamine : None
pyxlsb : None
s3fs : 2023.12.2
scipy : 1.13.0
sqlalchemy : 2.0.36
tables : 3.9.2
tabulate : 0.9.0
xarray : 2025.1.1
xlrd : 2.0.1
xlsxwriter : 3.2.0
zstandard : 0.23.0
tzdata : 2024.2
qtpy : None
pyqt5 : None