Skip to content

Commit b6236d9

Browse files
author
hhaensel
committed
fix pandas testing
1 parent a61c022 commit b6236d9

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

Project.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ UnsafePointers = "e17b2a0c-0bdf-430a-bd0c-3a23cae4ff39"
1919
[compat]
2020
Aqua = "0 - 999"
2121
CondaPkg = "0.2.23"
22+
DataFrames = "1.7.0"
2223
Dates = "1"
2324
Libdl = "1"
2425
MacroTools = "0.5"
@@ -35,8 +36,10 @@ julia = "1.6.1"
3536

3637
[extras]
3738
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
39+
CondaPkg = "992eb4ea-22a4-4c89-a5bb-47a3300528ab"
40+
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
3841
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3942
TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a"
4043

4144
[targets]
42-
test = ["Aqua", "Test", "TestItemRunner"]
45+
test = ["Aqua", "CondaPkg", "DataFrames", "Test", "TestItemRunner"]

test/Compat.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,14 @@ end
7979
end
8080

8181
@testitem "Tables.jl" begin
82+
using CondaPkg
83+
CondaPkg.add("pandas")
84+
8285
@testset "pytable" begin
8386
x = (x = [1, 2, 3], y = ["a", "b", "c"])
8487
# pandas
85-
# TODO: install pandas and test properly
86-
@test_throws PyException pytable(x, :pandas)
88+
t = pytable(x, :pandas)
89+
@test pyconvert.(Int, Tuple(t.shape)) == (3, 2)
8790
# columns
8891
y = pytable(x, :columns)
8992
@test pyeq(Bool, y, pydict(x = [1, 2, 3], y = ["a", "b", "c"]))

test/Wrap.jl

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -432,24 +432,26 @@ end
432432

433433
@testitem "PyPandasDataFrame" begin
434434
using Tables
435+
using DataFrames
436+
using CondaPkg
437+
CondaPkg.add("pandas")
435438
@test PyPandasDataFrame isa Type
436-
# TODO: figure out how to get pandas into the test environment
437-
# for now use some dummy type and take advantage of the fact that the code doesn't actually check it's a real dataframe
438-
@pyexec """
439-
class DataFrame:
440-
def __init__(self, **kw):
441-
self.__dict__.update(kw)
442-
""" => DataFrame
443-
df = DataFrame(shape = (4, 3), columns = pylist(["foo", "bar", "baz"]))
444-
x = PyPandasDataFrame(df)
439+
x = (x = [1, 2, 3], y = ["a", "b", "c"])
440+
py_df = pytable(x, :pandas)
441+
@test Tables.istable(PyTable(py_df))
442+
df = DataFrame(PyTable(py_df))
443+
@test df == DataFrame(x = [1, 2, 3], y = ["a", "b", "c"])
444+
445+
x = PyPandasDataFrame(py_df)
446+
df = DataFrame(x)
447+
@test df == DataFrame(x = [1, 2, 3], y = ["a", "b", "c"])
445448
@test ispy(x)
446-
@test Py(x) === df
447449
@test Tables.istable(x)
448450
@test Tables.columnaccess(x)
449-
@test_throws Exception Tables.columns(x)
451+
@test Tables.columns(x)[:x] == [1, 2, 3]
450452
@test_throws Exception pyconvert(PyPandasDataFrame, 1)
451453
str = sprint(show, MIME("text/plain"), x)
452-
@test occursin(r"4×3 .*PyPandasDataFrame", str)
454+
@test occursin(r"3×2 .*PyPandasDataFrame", str)
453455
end
454456

455457
@testitem "PySet" begin

0 commit comments

Comments
 (0)