-
Notifications
You must be signed in to change notification settings - Fork 24
/
test_copy.jl
43 lines (39 loc) · 1.43 KB
/
test_copy.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
40
41
42
43
module TestCopy
include("preamble.jl")
import Tables
using DataFrames: DataFrame, eachrow
using StructArrays: StructVector
using TypedTables: Table
@testset "copy [base types]" begin
@test copy(Map(x -> x^2), Vector, 1:3) == (1:3) .^ 2
@test copy(Map(x -> x^2), [1:3;]) == (1:3) .^ 2
@test copy(Map(x -> x^2), Set, 1:3) == Set((1:3) .^ 2)
@test copy(Map(x -> x => x^2), Dict, 2:2) == Dict(2 => 4)
end
@testset "$copy" for copy in [copy, tcopy, dcopy]
@testset "$copy(_, ::$(prettytypeof(src)))" for src in Any[
DataFrame(a=[1], b=[2]),
StructVector(a=[1:4;], b=[5:8;]),
Table(a=[1:4;], b=[5:8;]),
]
if copy in (tcopy, dcopy) && src isa DataFrame
@test_broken copy(Map(identity), src) ==ₜ src
@test_broken copy(Map(identity), src; basesize=1) ==ₜ src
continue
end
@test copy(Map(identity), src) ==ₜ src
if copy in (tcopy, dcopy)
@test copy(Map(identity), src; basesize=1) ==ₜ src
end
end
@testset "$copy(_, eachrow(df))" begin
df = DataFrame(a=[1:4;], b=[5:8;])
if Tables.materializer(eachrow(df)) == DataFrame || copy in (tcopy, dcopy)
@test copy(Map(identity), eachrow(df)) ==ₜ df
# requires https://github.com/JuliaData/DataFrames.jl/pull/2055
else
@test_broken copy(Map(identity), eachrow(df)) ==ₜ df
end
end
end
end # module