Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tests to Tables.jl v1.2 #2530

Merged
merged 4 commits into from
Nov 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@

## Dependency changes

* Tables.jl version 1.2 is now required.
* DataAPI.jl version 1.4 is now required. It implies that `All(args...)` is
deprecated and `Cols(args...)` is recommended instead. `All()` is still supported.

Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ PrettyTables = "0.10"
Reexport = "0.1, 0.2"
SortingAlgorithms = "0.1, 0.2, 0.3"
TableTraits = "0.4, 1"
Tables = "1.1"
Tables = "1.2"

[extras]
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Expand Down
20 changes: 12 additions & 8 deletions test/select.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1542,10 +1542,12 @@ end
DataFrame(p=Int[], q=String[]))

# here this follows Tables.jl behavior
for res in ([1, "1"], (1, "1"))
@test select(df, [] => ByRow(() -> res) => AsTable) == DataFrame()
@test_throws ArgumentError select(df, [] => ByRow(() -> res) => [:p, :q])
end
@test select(df, [] => ByRow(() -> [1, "1"]) => AsTable) == DataFrame()
@test_throws ArgumentError select(df, [] => ByRow(() -> [1, "1"]) => [:p, :q])
@test isequal_coltyped(select(df, [] => ByRow(() -> (1, "1")) => AsTable),
DataFrame(Column1=Int[], Column2=String[]))
@test isequal_coltyped(select(df, [] => ByRow(() -> (1, "1")) => [:p, :q]),
DataFrame(p=Int[], q=String[]))
Comment on lines +1545 to +1550
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why (1, "1") is treated differently from [1, "1"] now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because in Tables.jl 1.2 tuples have a schema (they have a fixed number of elements), while vectors do not have it (as they can have varying number of elements).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tuples now behave like NamedTuples but with auto-generated column names.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmmm, I don't quite follow what's going on here; how are (1, "1") and [1, "1"] being treated here? as an entire table? or as a single row? What (should have) changed in Tables.jl 1.2 is only the "empty" table case, where we will preserve the input schema if possible.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this is exactly what is tested here - if you look above these lines you will see that we are testing source data frames with 0 rows.

end

@test select(df, AsTable([]) => ByRow(x -> 1)) == DataFrame("function" => [1, 1, 1])
Expand All @@ -1570,10 +1572,12 @@ end
DataFrame(p=Int[], q=String[]))

# here this follows Tables.jl behavior
for res in ([1, "1"], (1, "1"))
@test select(df, AsTable([]) => ByRow(x -> res) => AsTable) == DataFrame()
@test_throws ArgumentError select(df, AsTable([]) => ByRow(x -> res) => [:p, :q])
end
@test select(df, [] => ByRow(() -> [1, "1"]) => AsTable) == DataFrame()
@test_throws ArgumentError select(df, [] => ByRow(() -> [1, "1"]) => [:p, :q])
@test isequal_coltyped(select(df, [] => ByRow(() -> (1, "1")) => AsTable),
DataFrame(Column1=Int[], Column2=String[]))
@test isequal_coltyped(select(df, [] => ByRow(() -> (1, "1")) => [:p, :q]),
DataFrame(p=Int[], q=String[]))
end
end

Expand Down
10 changes: 9 additions & 1 deletion test/tables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,15 @@ end
end

@testset "test constructor with vectors" begin
@test DataFrame(Any[]) == DataFrame()
@test_throws ArgumentError DataFrame(Any[])
df = DataFrame(typeof((1,1))[])
@test names(df) == ["Column1", "Column2"]
@test size(df) == (0, 2)
@test eltype(df.Column1) == Int
df = DataFrame(typeof((a=1, b=1))[])
@test names(df) == ["a", "b"]
@test size(df) == (0, 2)
@test eltype(df.a) == Int
@test DataFrame(Vector[], :auto) == DataFrame()
@test DataFrame(Pair{Symbol, Vector}[], :auto) == DataFrame()
@test DataFrame(Pair[]) == DataFrame()
Expand Down