Skip to content

BUG: Inconsistent datetime conversion behavior when constructing a DataFrame with Python datetimes. #55014

Closed
@raeganbarker

Description

@raeganbarker

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

from datetime import datetime

from pandas import DataFrame

date = datetime.now()

data = {
    'date1': date,
    'date2': [date, date],
}

df = DataFrame(data)

print(df.dtypes)

Issue Description

The date columns are not the same type (The case in 2.1.0).

date1    datetime64[us]
date2    datetime64[ns]

Expected Behavior

The date columns are the same type (The case in 2.0.3).

date1    datetime64[ns]
date2    datetime64[ns]

Installed Versions

INSTALLED VERSIONS ------------------ commit : ba1cccd python : 3.11.4.final.0 python-bits : 64 OS : Linux OS-release : 5.15.49-linuxkit-pr Version : #1 SMP PREEMPT Thu May 25 07:27:39 UTC 2023 machine : aarch64 processor : byteorder : little LC_ALL : None LANG : C.UTF-8 LOCALE : en_US.UTF-8

pandas : 2.1.0
numpy : 1.25.2
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 68.0.0
pip : 23.2.1
Cython : None
pytest : 7.4.0
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 3.1.2
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : None
pandas_datareader : None
bs4 : None
bottleneck : None
dataframe-api-compat: None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : 3.1.2
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : 2.0.20
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None

Metadata

Metadata

Labels

BugNon-Nanodatetime64/timedelta64 with non-nanosecond resolution

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions