Skip to content

Commit 34f35ce

Browse files
author
hhaensel
committed
fix pandas testing
1 parent 5abcf1d commit 34f35ce

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

test/Compat.jl

+5-2
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

+14-12
Original file line numberDiff line numberDiff line change
@@ -439,24 +439,26 @@ end
439439

440440
@testitem "PyPandasDataFrame" begin
441441
using Tables
442+
using DataFrames
443+
using CondaPkg
444+
CondaPkg.add("pandas")
442445
@test PyPandasDataFrame isa Type
443-
# TODO: figure out how to get pandas into the test environment
444-
# for now use some dummy type and take advantage of the fact that the code doesn't actually check it's a real dataframe
445-
@pyexec """
446-
class DataFrame:
447-
def __init__(self, **kw):
448-
self.__dict__.update(kw)
449-
""" => DataFrame
450-
df = DataFrame(shape = (4, 3), columns = pylist(["foo", "bar", "baz"]))
451-
x = PyPandasDataFrame(df)
446+
x = (x = [1, 2, 3], y = ["a", "b", "c"])
447+
py_df = pytable(x, :pandas)
448+
@test Tables.istable(PyTable(py_df))
449+
df = DataFrame(PyTable(py_df))
450+
@test df == DataFrame(x = [1, 2, 3], y = ["a", "b", "c"])
451+
452+
x = PyPandasDataFrame(py_df)
453+
df = DataFrame(x)
454+
@test df == DataFrame(x = [1, 2, 3], y = ["a", "b", "c"])
452455
@test ispy(x)
453-
@test Py(x) === df
454456
@test Tables.istable(x)
455457
@test Tables.columnaccess(x)
456-
@test_throws Exception Tables.columns(x)
458+
@test Tables.columns(x)[:x] == [1, 2, 3]
457459
@test_throws Exception pyconvert(PyPandasDataFrame, 1)
458460
str = sprint(show, MIME("text/plain"), x)
459-
@test occursin(r"4×3 .*PyPandasDataFrame", str)
461+
@test occursin(r"3×2 .*PyPandasDataFrame", str)
460462
end
461463

462464
@testitem "PySet" begin

0 commit comments

Comments
 (0)