Skip to content

BUG: broken datetime when using to_sql() #55005

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
teweihuang opened this issue Sep 4, 2023 · 2 comments
Closed
3 tasks done

BUG: broken datetime when using to_sql() #55005

teweihuang opened this issue Sep 4, 2023 · 2 comments
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@teweihuang
Copy link

teweihuang commented Sep 4, 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
import sqlite3

today = pd.to_datetime("2023/9/5")
ele = [1, 2, 3]
df = pd.DataFrame({'date': [today] * len(ele), 'data': ele})
df.set_index('date', inplace=True)

conn = sqlite3.connect('date.db')
df.to_sql('test_date', conn, if_exists='replace')
conn.close()

Issue Description

the date in db becoming like this : 1693843200

screenshot1 screenshot2

the same code was working properly in 2.0.3, the date was correctly identified into YYYY-mm-dd.

I understand it's suggested to use utc=True, but please don't just make db broken instantly, that hurts.

it would be appreciated if devs could take a look.

Expected Behavior

It should be identified as YYYY-mm-dd, in this case, 2023-09-05 00:00:00, when using .to_sql() saving in db.

Installed Versions

INSTALLED VERSIONS ------------------ commit : ba1cccd python : 3.11.5.final.0 python-bits : 64 OS : Windows OS-release : 10 Version : 10.0.22621 machine : AMD64 processor : AMD64 Family 23 Model 113 Stepping 0, AuthenticAMD byteorder : little LC_ALL : None LANG : None LOCALE : Chinese (Traditional)_Taiwan.950 pandas : 2.1.0 numpy : 1.25.2 pytz : 2023.3 dateutil : 2.8.2 setuptools : 68.1.2 pip : 23.2.1 Cython : None pytest : None hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : 4.9.3 html5lib : None pymysql : None psycopg2 : None jinja2 : None IPython : None pandas_datareader : None bs4 : 4.12.2 bottleneck : None dataframe-api-compat: None fastparquet : None fsspec : None gcsfs : None matplotlib : 3.7.2 numba : None numexpr : None odfpy : None openpyxl : None pandas_gbq : None pyarrow : None pyreadstat : None pyxlsb : None s3fs : None scipy : 1.11.2 sqlalchemy : None tables : None tabulate : None xarray : None xlrd : None zstandard : None tzdata : 2023.3 qtpy : None pyqt5 : None
@teweihuang teweihuang added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 4, 2023
@asishm
Copy link
Contributor

asishm commented Sep 5, 2023

Thanks for the report. Duplicate of #54877

@mroeschke
Copy link
Member

Thanks for the report. This will be fixed in 2.1.1

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

3 participants