BUG: to_sql fails with datetime.time values with sqlite fallback mode #8341

Closed
jorisvandenbossche opened this Issue Sep 21, 2014 · 8 comments

Comments

Projects
None yet
2 participants

Columns of datetime.time were not yet supported in sqlite fallback mode (as noted in #7567, and do work for sqlalchemy), but it now seems to fail silently with master (instead of raising an error).

Using:

import sqlite3
con = sqlite3.connect(':memory:')
dt = pd.date_range('2014-01-01', periods=10, freq='10h')
df = pd.DataFrame({'date':dt.date, 'time':dt.time})
df.to_sql('test_datetime', con, index=False, if_exists='replace')

gives:

In [37]: pd.read_sql_query('select * from test_datetime', con)
Out[37]: 
Empty DataFrame
Columns: [date, time]
Index: []

jorisvandenbossche added this to the 0.15.0 milestone Sep 21, 2014

Contributor

jreback commented Sep 30, 2014

@jorisvandenbossche pls move any sql issues you don't think can get to in next couple of days to 0.15.1 pls.

Contributor

jreback commented Oct 2, 2014

push?

@jreback I will have a look at the sql issues this evening and push if necessary

Contributor

jreback commented Oct 2, 2014

@jorisvandenbossche gr8 thanks

I will try to look at it this weekend

@jorisvandenbossche jorisvandenbossche modified the milestone: 0.16, 0.15.0 Oct 5, 2014

jorisvandenbossche changed the title from BUG: to_sql fails silently with column of datetime.time values with sqlite fallback mode to BUG: to_sql fails with datetime.time values with sqlite fallback mode Oct 5, 2014

See #8470 to fix the fact it fails silently. So now it will again just raise a InterfaceError: Error binding parameter 0 - probably unsupported type.
Changed title of issue to reflect that.

@jreback jreback modified the milestone: 0.16, 0.15.1 Oct 7, 2014

@jreback jreback modified the milestone: 0.16.0, Next Major Release Mar 6, 2015

@nbonnotte nbonnotte added a commit to nbonnotte/pandas that referenced this issue Feb 24, 2016

@nbonnotte nbonnotte BUG: to_sql with datetime.time values with sqlite, #8341
closes #8341
8d449c5

@jorisvandenbossche jorisvandenbossche added a commit that referenced this issue Feb 24, 2016

@nbonnotte @jorisvandenbossche nbonnotte + jorisvandenbossche BUG: to_sql with datetime.time values with sqlite
I'm proposing a solution to #8341    As @jorisvandenbossche suggested,
I use a sqlite3 adapter to transform `datetime.time` objects into
string (`hh:mm:ss.ffffff`, as this what sqlalchemy... I think?)    I
added a test in the class `_TestSQLApi`, so that the solution is
tested with both sqlalchemy and the sqlite3 fallback. Thus, the result
should be consistent.

Author: Nicolas Bonnotte <nicolas.bonnotte@gmail.com>

Closes #11547 from nbonnotte/sqlite-to_sql-time and squashes the following commits:

8d449c5 [Nicolas Bonnotte] BUG: to_sql with datetime.time values with sqlite, #8341
a652290

@jorisvandenbossche jorisvandenbossche modified the milestone: 0.18.0, Someday Feb 24, 2016

Closed by #11547

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment