11
22import math
33import numpy
4+ import sqlite3
45
56import data_algebra .util
67from data_algebra .data_ops import *
78import data_algebra .SQLite
89
910def test_null_bad ():
10- ops = TableDescription ("d" , ["x" ]).extend ({
11+ ops = TableDescription ("d" , ["x" ]).extend ({
1112 "x_is_null" : "x.is_null()" ,
1213 "x_is_bad" : "x.is_bad()"
1314 })
1415
1516 d = pandas .DataFrame ({
16- 'x' : [1 , numpy .nan , math .inf , - math .inf , None , 2 ]
17+ 'x' : [1 , numpy .nan , math .inf , - math .inf , None , 0 ]
1718 })
1819
1920 d2 = ops .transform (d )
2021
2122 expect = pandas .DataFrame ({
22- 'x' : [1 , numpy .nan , math .inf , - math .inf , None , 2 ],
23+ 'x' : [1 , numpy .nan , math .inf , - math .inf , None , 0 ],
2324 'x_is_null' : [False , True , False , False , True , False ],
2425 'x_is_bad' : [False , True , True , True , True , False ]
2526 })
@@ -31,3 +32,21 @@ def test_null_bad():
3132
3233 sql = ops .to_sql (db_model , pretty = True )
3334 assert isinstance (sql , str )
35+
36+ conn = sqlite3 .connect (":memory:" )
37+ db_model .prepare_connection (conn )
38+
39+ db_model .insert_table (conn , d , 'd' )
40+
41+ res = db_model .read_query (conn , sql )
42+
43+ conn .close ()
44+
45+ expectr = pandas .DataFrame ({
46+ 'x' : [1 , numpy .nan , math .inf , - math .inf , None , 0 ],
47+ 'x_is_null' : [0 , 1 , 0 , 0 , 1 , 0 ],
48+ 'x_is_bad' : [0 , 1 , 1 , 1 , 1 , 0 ]
49+ })
50+
51+ assert all (res ['x_is_null' ] == expectr ['x_is_null' ])
52+ assert all (res ['x_is_bad' ] == expectr ['x_is_bad' ])
0 commit comments