Skip to content

Commit

Permalink
Remove KeyedArray and AxisArray tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Glenn Moynihan committed Jun 18, 2021
1 parent a237977 commit c56a1a1
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 721 deletions.
96 changes: 0 additions & 96 deletions test/linear_combination.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,100 +29,4 @@
@test FeatureTransforms.apply(A, lc) == [2 11 20; 5 14 23; 8 17 26]
@test lc(A) == [2 11 20; 5 14 23; 8 17 26]
end

@testset "AxisArray" begin
A = AxisArray([1 2; 4 5], foo=["a", "b"], bar=["x", "y"])
lc = LinearCombination([1, -1])

@testset "all inds" begin
@test FeatureTransforms.apply(A, lc) == [-3, -3]
@test lc(A) == [-3, -3]
end

@testset "dims" begin
@testset "dims = :" begin
@test_deprecated FeatureTransforms.apply(A, lc; dims=:)
end

@testset "dims = 1" begin
@test FeatureTransforms.apply(A, lc; dims=1) == [-3, -3]
@test lc(A; dims=1) == [-3, -3]
end

@testset "dims = 2" begin
@test FeatureTransforms.apply(A, lc; dims=2) == [-1, -1]
@test lc(A; dims=2) == [-1, -1]
end
end

@testset "dimension mismatch" begin
A = AxisArray([1 2 3; 4 5 5], foo=["a", "b"], bar=["x", "y", "z"])
@test_throws DimensionMismatch FeatureTransforms.apply(A, lc; dims=2)
end

@testset "specified inds" begin
A = AxisArray([1 2 3; 4 5 5], foo=["a", "b"], bar=["x", "y", "z"])
@test FeatureTransforms.apply(A, lc; inds=[1, 2]) == [-3, -3, -2]
@test lc(A; inds=[1, 2]) == [-3, -3, -2]
end

@testset "apply_append" begin
A = AxisArray([1 2; 4 5], foo=["a", "b"], bar=["x", "y"])

expected1 = [1 2; 4 5; -3 -3]
@test FeatureTransforms.apply_append(A, lc; dims=1, append_dim=1) == expected1

expected2 = [1 2 -1; 4 5 -1]
@test FeatureTransforms.apply_append(A, lc; dims=2, append_dim=2) == expected2
end
end

@testset "AxisKey" begin
A = KeyedArray([1 2; 4 5], foo=["a", "b"], bar=["x", "y"])
lc = LinearCombination([1, -1])

@testset "all inds" begin
@test FeatureTransforms.apply(A, lc) == [-3, -3]
@test lc(A) == [-3, -3]
end

@testset "dims" begin
@testset "dims = :" begin
@test_deprecated FeatureTransforms.apply(A, lc; dims=:)
end

@testset "dims = 1" begin
@test FeatureTransforms.apply(A, lc; dims=1) == [-3, -3]
@test FeatureTransforms.apply(A, lc; dims=:foo) == [-3, -3]
@test lc(A; dims=1) == [-3, -3]
end

@testset "dims = 2" begin
@test FeatureTransforms.apply(A, lc; dims=2) == [-1, -1]
@test FeatureTransforms.apply(A, lc; dims=:bar) == [-1, -1]
@test lc(A; dims=2) == [-1, -1]
end
end

@testset "dimension mismatch" begin
A = KeyedArray([1 2 3; 4 5 6], foo=["a", "b"], bar=["x", "y", "z"])
@test_throws DimensionMismatch FeatureTransforms.apply(A, lc; dims=2)
end

@testset "specified inds" begin
A = KeyedArray([1 2 3; 4 5 5], foo=["a", "b"], bar=["x", "y", "z"])
@test FeatureTransforms.apply(A, lc; inds=[1, 2]) == [-3, -3, -2]
@test lc(A; inds=[1, 2]) == [-3, -3, -2]
end

@testset "apply_append" begin
A = KeyedArray([1 2; 4 5], foo=["a", "b"], bar=["x", "y"])

expected1 = [1 2; 4 5; -3 -3]
@test FeatureTransforms.apply_append(A, lc; dims=:foo, append_dim=:foo) == expected1

expected2 = [1 2 -1; 4 5 -1]
@test FeatureTransforms.apply_append(A, lc; dims=:bar, append_dim=:bar) == expected2
end
end
end
56 changes: 0 additions & 56 deletions test/one_hot_encoding.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,60 +29,4 @@
@test_throws KeyError FeatureTransforms.apply(x, ohe)
end
end

@testset "AxisArray" begin
categories = ["foo", "bar", "baz", "foo2", "bar2"]
ohe = OneHotEncoding(categories)

M = ["foo" "bar"; "foo2" "bar2"]
A = AxisArray(M, foo=["a", "b"], bar=["x", "y"])
expected = [1 0 0 0 0; 0 0 0 1 0; 0 1 0 0 0; 0 0 0 0 1]

@testset "dims = $d" for d in (1, 2, Colon())
transformed = FeatureTransforms.apply(A, ohe; dims=d)
# AxisArray doesn't preserve the type it operates on
@test transformed isa AbstractArray
@test transformed == expected
end

@testset "inds" begin
@test FeatureTransforms.apply(A, ohe; inds=[2, 3]) == [0 0 0 1 0; 0 1 0 0 0]
@test FeatureTransforms.apply(A, ohe; dims=:, inds=[2, 3]) == [0 0 0 1 0; 0 1 0 0 0]
end

@testset "apply_append" begin
M = ["foo" "bar"; "foo2" "bar2"]
A = AxisArray(M, foo=["a", "b"], bar=["x", "y"])
@test_throws DimensionMismatch FeatureTransforms.apply_append(A, ohe; append_dim=1)
@test_throws DimensionMismatch FeatureTransforms.apply_append(A, ohe; append_dim=2)
end
end

@testset "AxisKey" begin
categories = ["foo", "bar", "baz", "foo2", "bar2"]
ohe = OneHotEncoding(categories)

M = ["foo" "bar"; "foo2" "bar2"]
A = KeyedArray(M, foo=["a", "b"], bar=["x", "y"])
expected = [1 0 0 0 0; 0 0 0 1 0; 0 1 0 0 0; 0 0 0 0 1]

@testset "dims = $d" for d in (1, 2, Colon(), :foo, :bar)
transformed = FeatureTransforms.apply(A, ohe; dims=d)
# This transform doesn't preserve the type it operates on
@test transformed isa AbstractArray
@test transformed == expected
end

@testset "inds" begin
@test FeatureTransforms.apply(A, ohe; inds=[2, 3]) == [0 0 0 1 0; 0 1 0 0 0]
@test FeatureTransforms.apply(A, ohe; dims=:, inds=[2, 3]) == [0 0 0 1 0; 0 1 0 0 0]
end

@testset "apply_append" begin
M = ["foo" "bar"; "foo2" "bar2"]
A = KeyedArray(M, foo=["a", "b"], bar=["x", "y"])
@test_throws DimensionMismatch FeatureTransforms.apply_append(A, ohe; append_dim=:foo)
@test_throws DimensionMismatch FeatureTransforms.apply_append(A, ohe; append_dim=:bar)
end
end
end
159 changes: 0 additions & 159 deletions test/periodic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,120 +78,6 @@
@test p(x) [0.0, 1.0, -1.0] atol=1e-14
end
end

expected_dict = Dict(
sin => [
-0.5877852522924732,
-0.9510565162951535,
0.0,
0.9510565162951535,
0.5877852522924732,
-0.58778525229247
],
cos => [
-0.8090169943749473,
0.30901699437494745,
1.0,
0.30901699437494745,
-0.8090169943749473,
-0.8090169943749475
]
)

@testset "$f" for f in (sin, cos)
expected = expected_dict[f]
p = Periodic(f, 5, 2)

@testset "AxisArray" begin
x = collect(0.:5.)
A = AxisArray(reshape(x, (3, 2)), foo=["a", "b", "c"], bar=["x", "y"])

A_expected = AxisArray(
reshape(expected, (3, 2)),
foo=["a", "b", "c"],
bar=["x", "y"]
)

@testset "dims = $d" for d in (Colon(), 1, 2)
transformed = FeatureTransforms.apply(A, p; dims=d)
# AxisArray doesn't preserve type when operations are performed on it
@test transformed isa AbstractArray
@test transformed A_expected atol=1e-14
end

_A = copy(A)
FeatureTransforms.apply!(_A, p)
@test _A isa AxisArray
@test _A A_expected atol=1e-14

@testset "inds" begin
@test FeatureTransforms.apply(A, p; inds=[2, 3]) A_expected[[2, 3]] atol=1e-14
@test FeatureTransforms.apply(A, p; dims=:, inds=[2, 3]) A_expected[[2, 3]] atol=1e-14
@test FeatureTransforms.apply(A, p; dims=1, inds=[2]) reshape(A_expected[[2, 5]], 1, 2) atol=1e-14
@test FeatureTransforms.apply(A, p; dims=2, inds=[2]) reshape(A_expected[[4, 5, 6]], 3, 1) atol=1e-14
end

@testset "append_apply" begin
exp1 = vcat(A, A_expected)
@test FeatureTransforms.apply_append(A, p, append_dim=1) exp1 atol=1e-14
exp2 = hcat(A, A_expected)
@test FeatureTransforms.apply_append(A, p, append_dim=2) exp2 atol=1e-14
exp3 = cat(A, A_expected, dims=3)
@test FeatureTransforms.apply_append(A, p, append_dim=3) exp3 atol=1e-14
end
end

@testset "AxisKey" begin
x = collect(0.:5.)
A = KeyedArray(reshape(x, (3, 2)), foo=["a", "b", "c"], bar=["x", "y"])

A_expected = KeyedArray(
reshape(expected, (3, 2)),
foo=["a", "b", "c"],
bar=["x", "y"]
)

@testset "dims = $d" for d in (Colon(), :foo, :bar)
transformed = FeatureTransforms.apply(A, p; dims=d)
@test transformed isa KeyedArray
@test transformed A_expected atol=1e-14
end

_A = copy(A)
FeatureTransforms.apply!(_A, p)
@test _A A_expected atol=1e-14

@testset "inds" begin
@test FeatureTransforms.apply(A, p; inds=[2, 3]) [A_expected[2], A_expected[3]] atol=1e-14
@test FeatureTransforms.apply(A, p; dims=:, inds=[2, 3]) [A_expected[2], A_expected[3]] atol=1e-14
@test FeatureTransforms.apply(A, p; dims=1, inds=[2]) reshape([A_expected[2], A_expected[5]], 1, 2) atol=1e-14
@test FeatureTransforms.apply(A, p; dims=2, inds=[2]) reshape([A_expected[4], A_expected[5], A_expected[6]], 3, 1) atol=1e-14
end

@testset "append_apply" begin
M = reshape(x, (3, 2))
M_expected = reshape(expected, (3, 2))

exp1 = KeyedArray(
vcat(M, M_expected), foo=["a", "b", "c", "a", "b", "c"], bar=["x", "y"]
)
@test FeatureTransforms.apply_append(A, p, append_dim=:foo) exp1 atol=1e-14

exp2 = KeyedArray(
hcat(M, M_expected), foo=["a", "b", "c"], bar=["x", "y", "x", "y"]
)
@test FeatureTransforms.apply_append(A, p, append_dim=:bar) exp2 atol=1e-14

exp3 = KeyedArray(
cat(M, M_expected, dims=3),
foo=["a", "b", "c"],
bar=["x", "y"],
baz=Base.OneTo(2)
)
@test FeatureTransforms.apply_append(A, p, append_dim=:baz) exp3 atol=1e-14
end
end
end
end

@testset "TimeType input" begin
Expand Down Expand Up @@ -239,51 +125,6 @@
@test FeatureTransforms.apply(x, p) expected atol=1e-14
@test p(x) expected atol=1e-14
end

@testset "AxisArray" begin
x = ZonedDateTime(2020, 1, 1, tz"EST") .+ (Day(0):Day(1):Day(5))
A = AxisArray(
reshape(x, (3, 2)),
foo=["a", "b", "c"],
bar=["x", "y"]
)

expected = _periodic.(f, x, Day(5), Day(2))
expected = AxisArray(
reshape(expected, (3, 2)),
foo=["a", "b", "c"],
bar=["x", "y"]
)

@testset "dims = $d" for d in (Colon(), 1, 2)
transformed = FeatureTransforms.apply(A, p; dims=d)
# AxisArray doesn't preserve type when operations are performed on it
@test transformed isa AbstractArray
@test transformed expected atol=1e-14
end
end

@testset "AxisKey" begin
x = ZonedDateTime(2020, 1, 1, tz"EST") .+ (Day(0):Day(1):Day(5))
A = KeyedArray(
reshape(x, (3, 2)),
foo=["a", "b", "c"],
bar=["x", "y"]
)

expected = _periodic.(f, x, Day(5), Day(2))
expected = KeyedArray(
reshape(expected, (3, 2)),
foo=["a", "b", "c"],
bar=["x", "y"]
)

@testset "dims = $d" for d in (Colon(), :foo, :bar, 1, 2)
transformed = FeatureTransforms.apply(A, p; dims=d)
@test transformed isa KeyedArray
@test transformed expected atol=1e-14
end
end
end
end

Expand Down
Loading

0 comments on commit c56a1a1

Please sign in to comment.