Skip to content

BUG: pd.concat raises ValueError if I have the same column with datetime.datetime type and pd.Timestamp type. #55024

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

Closed
3 tasks done
WindSoilder opened this issue Sep 6, 2023 · 1 comment
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@WindSoilder
Copy link

WindSoilder commented Sep 6, 2023

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
a = pd.DataFrame({'a': [pd.Timestamp("2023-01-01")]})
b = pd.DataFrame(index=[1])
b['a'] = datetime(2023, 1, 2)
pd.concat([a, b])

Issue Description

It seems that pd.concat runs to failed because a.a and b.a have two different dtypes.

a.a is datetime64[ns], but b.a is datetime64[us].

But it's strange..I think pd.Timestamp and datetime.datetime should be the same thing at user level.

Actually the following one is failed too:

import pandas as pd
a = pd.DataFrame({'a': [pd.Timestamp("2023-01-01")]})
b = pd.DataFrame(index=[1])
b['a'] = pd.Timestamp("2023-01-01")
pd.concat([a, b])

Only the following is fine:

import pandas as pd
a = pd.DataFrame({'a': [pd.Timestamp("2023-01-01")]})
b = pd.DataFrame({'a': [pd.Timestamp("2023-01-01")]}, index=[1])
pd.concat([a, b])

Expected Behavior

I'd expected it runs to success, it runs success on 2.0.3.

Installed Versions

INSTALLED VERSIONS

commit : a6445df
python : 3.11.0.final.0
python-bits : 64
OS : Darwin
OS-release : 22.4.0
Version : Darwin Kernel Version 22.4.0: Mon Mar 6 21:00:17 PST 2023; root:xnu-8796.101.5~3/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.UTF-8

pandas : 2.1.0+22.ga6445df90
numpy : 1.24.2
pytz : 2022.7.1
dateutil : 2.8.2
setuptools : 65.5.0
pip : 22.2.2
Cython : 0.29.36
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : 1.0.2
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.12.0
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 : 12.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.10.1
sqlalchemy : 1.4.39
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : 0.20.0
tzdata : 2023.3
qtpy : None
pyqt5 : None

@WindSoilder WindSoilder added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 6, 2023
@WindSoilder
Copy link
Author

WindSoilder commented Sep 7, 2023

Closing this because it's duplicate #53640

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

1 participant