Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Inconsistent datetime dtype precision with assign() using list vs direct value #56733

Closed
3 tasks done
glichtner opened this issue Jan 4, 2024 · 2 comments · Fixed by #55901
Closed
3 tasks done
Labels
Bug Non-Nano datetime64/timedelta64 with non-nanosecond resolution

Comments

@glichtner
Copy link

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
import datetime

dt = datetime.datetime(2024, 1, 4, 12, 0, 0)

df = pd.DataFrame(index=[0])

df_list = df.assign(datetime=[dt])
df_value = df.assign(datetime=dt)

pd.testing.assert_frame_equal(df_list, df_value)

Issue Description

The dtype of the datetime column should be the same in both cases, but it is different:

AssertionError: Attributes of DataFrame.iloc[:, 0] (column name="datetime") are different

Attribute "dtype" are different
[left]:  datetime64[ns]
[right]: datetime64[us]

Expected Behavior

No assertion error.

Installed Versions

INSTALLED VERSIONS

commit : 2522b0a
python : 3.11.5.final.0
python-bits : 64
OS : Linux
OS-release : 6.5.0-14-generic
Version : #14-Ubuntu SMP PREEMPT_DYNAMIC Tue Nov 14 14:59:49 UTC 2023
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 2.3.0.dev0+43.g2522b0ab1b
numpy : 2.0.0.dev0+git20240102.d906b52
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 68.2.2
pip : 23.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 : 8.15.0
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.4
qtpy : None
pyqt5 : None

@glichtner glichtner added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jan 4, 2024
@jbrockmendel jbrockmendel added the Non-Nano datetime64/timedelta64 with non-nanosecond resolution label Jan 4, 2024
@jbrockmendel
Copy link
Member

Should be addressed by #55901

@rhshadrach rhshadrach removed the Needs Triage Issue that has not been reviewed by a pandas team member label Jan 4, 2024
@sh00tToMiss
Copy link

Hello,

I was looking into this issue and was wondering which dtype would be correct? By this I mean, should both return as datetime64[us] or datetime64[ns]?

Could you perhaps help me @jbrockmendel ?

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Non-Nano datetime64/timedelta64 with non-nanosecond resolution
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants