@@ -1429,6 +1429,22 @@ def test_datetime_time(self):
1429
1429
res = read_sql_table ('test_time' , self .conn )
1430
1430
tm .assert_frame_equal (res , df )
1431
1431
1432
+ # GH8341
1433
+ # first, use the fallback to have the sqlite adapter put in place
1434
+ sqlite_conn = TestSQLiteFallback .connect ()
1435
+ sql .to_sql (df , "test_time2" , sqlite_conn , index = False )
1436
+ res = sql .read_sql_query ("SELECT * FROM test_time2" , sqlite_conn )
1437
+ ref = df .applymap (lambda _ : _ .strftime ("%H:%M:%S.%f" ))
1438
+ tm .assert_frame_equal (ref , res ) # check if adapter is in place
1439
+ # then test if sqlalchemy is unaffected by the sqlite adapter
1440
+ sql .to_sql (df , "test_time3" , self .conn , index = False )
1441
+ if self .flavor == 'sqlite' :
1442
+ res = sql .read_sql_query ("SELECT * FROM test_time3" , self .conn )
1443
+ ref = df .applymap (lambda _ : _ .strftime ("%H:%M:%S.%f" ))
1444
+ tm .assert_frame_equal (ref , res )
1445
+ res = sql .read_sql_table ("test_time3" , self .conn )
1446
+ tm .assert_frame_equal (df , res )
1447
+
1432
1448
def test_mixed_dtype_insert (self ):
1433
1449
# see GH6509
1434
1450
s1 = Series (2 ** 25 + 1 , dtype = np .int32 )
@@ -1957,12 +1973,14 @@ def test_datetime_date(self):
1957
1973
tm .assert_frame_equal (res , df )
1958
1974
1959
1975
def test_datetime_time (self ):
1960
- # test support for datetime.time
1976
+ # test support for datetime.time, GH #8341
1961
1977
df = DataFrame ([time (9 , 0 , 0 ), time (9 , 1 , 30 )], columns = ["a" ])
1962
- # test it raises an error and not fails silently (GH8341)
1978
+ df .to_sql ('test_time' , self .conn , index = False , flavor = self .flavor )
1979
+ res = read_sql_query ('SELECT * FROM test_time' , self .conn )
1963
1980
if self .flavor == 'sqlite' :
1964
- self .assertRaises (sqlite3 .InterfaceError , sql .to_sql , df ,
1965
- 'test_time' , self .conn )
1981
+ # comes back as strings
1982
+ expected = df .applymap (lambda _ : _ .strftime ("%H:%M:%S.%f" ))
1983
+ tm .assert_frame_equal (res , expected )
1966
1984
1967
1985
def _get_index_columns (self , tbl_name ):
1968
1986
ixs = sql .read_sql_query (
0 commit comments