-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathdataframes_impl.jl
39 lines (34 loc) · 1.44 KB
/
dataframes_impl.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import DataFrames
import DataArrays: isna
function test_dataframes()
df = connect(Postgres, "localhost", "postgres", "", "julia_test") do conn
stmt = prepare(conn, "SELECT 4::integer as foo, 4.0::DOUBLE PRECISION as bar, " *
"NULL::integer as foobar;")
result = execute(stmt)
return fetchdf(result)
end
@test isa(df, DataFrames.DataFrame)
@test df[:foo] == Int32[4]
@test df[:bar] == Float64[4.0]
@test isna(df[:foobar][1])
df2 = connect(Postgres, "localhost", "postgres", "", "julia_test") do conn
run(conn, """CREATE TEMPORARY TABLE dftable (foo integer, bar double precision,
foobar integer);""")
testdberror(conn, PostgreSQL.CONNECTION_OK)
# stmt = prepare(conn, "INSERT INTO dftable (foo, bar, foobar) VALUES (\$1, \$2, \$3);")
run(conn, "INSERT INTO dftable (foo, bar, foobar) VALUES (4, 4.0, NULL);")
testdberror(conn, PostgreSQL.CONNECTION_OK)
# executemany(stmt, Vector[{4, 4.0, 4}])
# testdberror(stmt, PostgreSQL.PGRES_COMMAND_OK)
stmt = prepare(conn, "SELECT * FROM dftable;")
result = execute(stmt)
return fetchdf(result)
end
@test names(df) == names(df2)
for col in names(df)
@test all(isna(df[col]) == isna(df2[col]))
@test all(i -> (isna(df[col][i]) && isna(df2[col][i])) || (df[col][i] == df2[col][i]),
1:length(df[col]))
end
end
test_dataframes()