Skip to content

Commit

Permalink
fix pandas testing
Browse files Browse the repository at this point in the history
  • Loading branch information
hhaensel committed Jan 21, 2025
1 parent 5abcf1d commit 34f35ce
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
7 changes: 5 additions & 2 deletions test/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,14 @@ end
end

@testitem "Tables.jl" begin
using CondaPkg
CondaPkg.add("pandas")

@testset "pytable" begin
x = (x = [1, 2, 3], y = ["a", "b", "c"])
# pandas
# TODO: install pandas and test properly
@test_throws PyException pytable(x, :pandas)
t = pytable(x, :pandas)
@test pyconvert.(Int, Tuple(t.shape)) == (3, 2)
# columns
y = pytable(x, :columns)
@test pyeq(Bool, y, pydict(x = [1, 2, 3], y = ["a", "b", "c"]))
Expand Down
26 changes: 14 additions & 12 deletions test/Wrap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -439,24 +439,26 @@ end

@testitem "PyPandasDataFrame" begin
using Tables
using DataFrames
using CondaPkg
CondaPkg.add("pandas")
@test PyPandasDataFrame isa Type
# TODO: figure out how to get pandas into the test environment
# for now use some dummy type and take advantage of the fact that the code doesn't actually check it's a real dataframe
@pyexec """
class DataFrame:
def __init__(self, **kw):
self.__dict__.update(kw)
""" => DataFrame
df = DataFrame(shape = (4, 3), columns = pylist(["foo", "bar", "baz"]))
x = PyPandasDataFrame(df)
x = (x = [1, 2, 3], y = ["a", "b", "c"])
py_df = pytable(x, :pandas)
@test Tables.istable(PyTable(py_df))
df = DataFrame(PyTable(py_df))
@test df == DataFrame(x = [1, 2, 3], y = ["a", "b", "c"])

x = PyPandasDataFrame(py_df)
df = DataFrame(x)
@test df == DataFrame(x = [1, 2, 3], y = ["a", "b", "c"])
@test ispy(x)
@test Py(x) === df
@test Tables.istable(x)
@test Tables.columnaccess(x)
@test_throws Exception Tables.columns(x)
@test Tables.columns(x)[:x] == [1, 2, 3]
@test_throws Exception pyconvert(PyPandasDataFrame, 1)
str = sprint(show, MIME("text/plain"), x)
@test occursin(r"4×3 .*PyPandasDataFrame", str)
@test occursin(r"3×2 .*PyPandasDataFrame", str)
end

@testitem "PySet" begin
Expand Down

0 comments on commit 34f35ce

Please sign in to comment.