Skip to content

Commit

Permalink
Ensure TestFakes can return a KeyedArray
Browse files Browse the repository at this point in the history
Needed downstream in AxisSets.
Note this doesn't apply to AxisArrays.
  • Loading branch information
Glenn Moynihan committed Apr 21, 2021
1 parent 5da6ca5 commit 11e9117
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "FeatureTransforms"
uuid = "8fd68953-04b8-4117-ac19-158bf6de9782"
authors = ["Invenia Technical Computing Corporation"]
version = "0.3.4"
version = "0.3.5"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
10 changes: 5 additions & 5 deletions src/test_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ for C in (:OneToOne, :OneToMany, :ManyToOne, :ManyToMany)
end

function FeatureTransforms._apply(A, ::FakeOneToOneTransform; kwargs...)
return ones(size(A))
return replace(one, A)
end

function FeatureTransforms._apply(A, ::FakeOneToManyTransform; kwargs...)
return hcat(ones(size(A)), ones(size(A)))
return hcat(replace(one, A), replace(one, A))
end

function FeatureTransforms._apply(A, ::FakeManyToOneTransform; dims, kwargs...)
return ones(size(first(A)))
function FeatureTransforms._apply(A, ::FakeManyToOneTransform; kwargs...)
return replace(one, first(A))
end

function FeatureTransforms._apply(A, ::FakeManyToManyTransform; kwargs...)
return hcat(ones(size(A)), ones(size(A)))
return hcat(replace(one, A), replace(one, A))
end

"""
Expand Down
28 changes: 28 additions & 0 deletions test/test_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ using FeatureTransforms.TestUtils

M = reshape(1:9, 3, 3)
@test FeatureTransforms.apply(M, t) == ones(3, 3)

# TODO: remove when refactoring tests
M = KeyedArray(M; a=["a", "b", "c"], b=[:x, :y, :z])
expected = KeyedArray(ones(3, 3); a=["a", "b", "c"], b=[:x, :y, :z])
result = FeatureTransforms.apply(M, t)
@test result == expected
@test result isa KeyedArray
end

@testset "FakeOneToManyTransform" begin
Expand All @@ -22,6 +29,13 @@ using FeatureTransforms.TestUtils

M = reshape(1:9, 3, 3)
@test FeatureTransforms.apply(M, t) == ones(3, 6)

# TODO: remove when refactoring tests
M = KeyedArray(M; a=["a", "b", "c"], b=[:x, :y, :z])
expected = KeyedArray(ones(3, 6); a=["a", "b", "c"], b=[:x, :y, :z, :x, :y, :z])
result = FeatureTransforms.apply(M, t)
@test result == expected
@test result isa KeyedArray
end

@testset "FakeManyToOneTransform" begin
Expand All @@ -33,6 +47,13 @@ using FeatureTransforms.TestUtils

M = reshape(1:9, 3, 3)
@test FeatureTransforms.apply(M, t; dims=1) == ones(3)

# TODO: remove when refactoring tests
M = KeyedArray(M; a=["a", "b", "c"], b=[:x, :y, :z])
expected = KeyedArray(ones(3); a=["a", "b", "c"])
result = FeatureTransforms.apply(M, t; dims=:b)
@test result == expected
@test result isa KeyedArray
end

@testset "FakeManyToManyTransform" begin
Expand All @@ -44,6 +65,13 @@ using FeatureTransforms.TestUtils

M = reshape(1:9, 3, 3)
@test FeatureTransforms.apply(M, t) == ones(3, 6)

# TODO: remove when refactoring tests
M = KeyedArray(M; a=["a", "b", "c"], b=[:x, :y, :z])
expected = KeyedArray(ones(3, 6); a=["a", "b", "c"], b=[:x, :y, :z, :x, :y, :z])
result = FeatureTransforms.apply(M, t)
@test result == expected
@test result isa KeyedArray
end


Expand Down

0 comments on commit 11e9117

Please sign in to comment.