@@ -486,8 +486,8 @@ def test_timedelta(self):
486
486
with tm .assert_produces_warning (UserWarning ):
487
487
df .to_sql ('test_timedelta' , self .conn )
488
488
result = sql .read_sql_query ('SELECT * FROM test_timedelta' , self .conn )
489
- tm .assert_series_equal (result ['foo' ], df ['foo' ].astype ('int64' ))
490
-
489
+ tm .assert_series_equal (result ['foo' ], df ['foo' ].astype ('int64' ))
490
+
491
491
def test_to_sql_index_label (self ):
492
492
temp_frame = DataFrame ({'col1' : range (4 )})
493
493
@@ -893,6 +893,34 @@ def test_datetime(self):
893
893
else :
894
894
tm .assert_frame_equal (result , df )
895
895
896
+ def test_datetime_NaT (self ):
897
+ # status:
898
+ # - postgresql: gives error on inserting "0001-255-255T00:00:00"
899
+ # - sqlite3: works, but reading it with query returns '-001--1--1 -1:-1:-1.-00001'
900
+
901
+ if self .driver == 'pymysql' :
902
+ raise nose .SkipTest ('writing datetime not working with pymysql' )
903
+ if self .driver == 'psycopg2' :
904
+ raise nose .SkipTest ('writing datetime NaT not working with psycopg2' )
905
+
906
+ df = DataFrame ({'A' : date_range ('2013-01-01 09:00:00' , periods = 3 ),
907
+ 'B' : np .arange (3.0 )})
908
+ df .loc [1 , 'A' ] = np .nan
909
+ df .to_sql ('test_datetime' , self .conn , index = False )
910
+
911
+ # with read_table -> type information from schema used
912
+ result = sql .read_sql_table ('test_datetime' , self .conn )
913
+ tm .assert_frame_equal (result , df )
914
+
915
+ # with read_sql -> no type information -> sqlite has no native
916
+ result = sql .read_sql_query ('SELECT * FROM test_datetime' , self .conn )
917
+ if self .flavor == 'sqlite' :
918
+ self .assertTrue (isinstance (result .loc [0 , 'A' ], string_types ))
919
+ result ['A' ] = to_datetime (result ['A' ], coerce = True )
920
+ tm .assert_frame_equal (result , df )
921
+ else :
922
+ tm .assert_frame_equal (result , df )
923
+
896
924
def test_mixed_dtype_insert (self ):
897
925
# see GH6509
898
926
s1 = Series (2 ** 25 + 1 ,dtype = np .int32 )
@@ -905,6 +933,63 @@ def test_mixed_dtype_insert(self):
905
933
906
934
tm .assert_frame_equal (df , df2 , check_dtype = False , check_exact = True )
907
935
936
+ def test_nan_numeric (self ):
937
+ if self .driver == 'pymysql' :
938
+ raise nose .SkipTest ('writing NaNs not working with pymysql' )
939
+
940
+ # NaNs in numeric float column
941
+ df = DataFrame ({'A' :[0 , 1 , 2 ], 'B' :[0.2 , np .nan , 5.6 ]})
942
+ df .to_sql ('test_nan' , self .conn , index = False )
943
+
944
+ # with read_table
945
+ result = sql .read_sql_table ('test_nan' , self .conn )
946
+ tm .assert_frame_equal (result , df )
947
+
948
+ # with read_sql
949
+ result = sql .read_sql_query ('SELECT * FROM test_nan' , self .conn )
950
+ tm .assert_frame_equal (result , df )
951
+
952
+ def test_nan_fullcolumn (self ):
953
+ if self .driver == 'pymysql' :
954
+ raise nose .SkipTest ('writing NaNs not working with pymysql' )
955
+
956
+ # full NaN column (numeric float column)
957
+ df = DataFrame ({'A' :[0 , 1 , 2 ], 'B' :[np .nan , np .nan , np .nan ]})
958
+ df .to_sql ('test_nan' , self .conn , index = False )
959
+
960
+ if self .flavor == 'sqlite' :
961
+ df ['B' ] = df ['B' ].astype ('object' )
962
+ df ['B' ] = None
963
+
964
+ # with read_table
965
+ result = sql .read_sql_table ('test_nan' , self .conn )
966
+ tm .assert_frame_equal (result , df )
967
+
968
+ # with read_sql
969
+ result = sql .read_sql_query ('SELECT * FROM test_nan' , self .conn )
970
+ tm .assert_frame_equal (result , df )
971
+
972
+ def test_nan_string (self ):
973
+ if self .driver == 'pymysql' :
974
+ raise nose .SkipTest ('writing NaNs not working with pymysql' )
975
+
976
+ # NaNs in string column
977
+ df = DataFrame ({'A' :[0 , 1 , 2 ], 'B' :['a' , 'b' , np .nan ]})
978
+ df .to_sql ('test_nan' , self .conn , index = False )
979
+
980
+ if self .flavor == 'sqlite' :
981
+ df .loc [2 , 'B' ] = None
982
+ elif self .flavor == 'postgresql' :
983
+ df = df .fillna ('NaN' )
984
+
985
+ # with read_table
986
+ result = sql .read_sql_table ('test_nan' , self .conn )
987
+ tm .assert_frame_equal (result , df )
988
+
989
+ # with read_sql
990
+ result = sql .read_sql_query ('SELECT * FROM test_nan' , self .conn )
991
+ tm .assert_frame_equal (result , df )
992
+
908
993
909
994
class TestSQLiteAlchemy (_TestSQLAlchemy ):
910
995
"""
0 commit comments