From cfac90e02c19b764c88847d205498e17e29a4446 Mon Sep 17 00:00:00 2001 From: Glenn Moynihan Date: Wed, 30 Jun 2021 13:58:07 +0100 Subject: [PATCH 1/5] Fix failing XArray tests The issue was in calling `cat` on AxisArrays and KeyedArrays. For AxisArrays the issue was it wouldn't allow two arrays to have the same axis values. KeyedArrays allows cat-ing two arrays with the same values but the default axis keys generated in the tests did not match those from the code. --- src/apply.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/apply.jl b/src/apply.jl index cf69bd5..dbbe977 100644 --- a/src/apply.jl +++ b/src/apply.jl @@ -118,7 +118,8 @@ the usual [`Transform`](@ref) being invoked. function apply_append(A::AbstractArray, t; append_dim, kwargs...)::AbstractArray result = apply(A, t; kwargs...) result = _postformat(cardinality(t), result, A, append_dim) - return cat(A, result; dims=append_dim) + # Call parent to avoid clashing axis/key names in concatenated result + return cat(A, parent(result); dims=append_dim) end """ @@ -153,5 +154,5 @@ _postformat(::Cardinality, result, A, append_dim) = result function _postformat(::ManyToOne, result, A, append_dim) new_size = collect(size(A)) setindex!(new_size, 1, dim(A, append_dim)) - return reshape(result, new_size...) + return copy(reshape(result, new_size...)) # return a copy to remove the reshape type end From 3b27080f31183da5358ebe98da0f7f8427807005 Mon Sep 17 00:00:00 2001 From: Glenn Moynihan Date: Thu, 1 Jul 2021 13:25:49 +0100 Subject: [PATCH 2/5] test on NamedDimsArrays --- test/types/xarray.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/types/xarray.jl b/test/types/xarray.jl index f8bccdc..b7eac33 100644 --- a/test/types/xarray.jl +++ b/test/types/xarray.jl @@ -1,4 +1,4 @@ -@testset "$ArrayType" for ArrayType in (AxisArray, KeyedArray) +@testset "$ArrayType" for ArrayType in (AxisArray, KeyedArray, NamedDimsArray) x = ArrayType([1 2 3; 4 5 6], foo=["a", "b"], bar=[:x, :y, :z]) @@ -114,7 +114,7 @@ end - if ArrayType == KeyedArray + if ArrayType != AxisArray @testset "indexing with dims" begin T = FakeOneToOneTransform() From c7d687bfab4ba81bccf8603c4f105369c818c404 Mon Sep 17 00:00:00 2001 From: Glenn Moynihan Date: Thu, 1 Jul 2021 13:58:41 +0100 Subject: [PATCH 3/5] call Matrix instead of parent --- src/apply.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/apply.jl b/src/apply.jl index dbbe977..8837c27 100644 --- a/src/apply.jl +++ b/src/apply.jl @@ -118,8 +118,8 @@ the usual [`Transform`](@ref) being invoked. function apply_append(A::AbstractArray, t; append_dim, kwargs...)::AbstractArray result = apply(A, t; kwargs...) result = _postformat(cardinality(t), result, A, append_dim) - # Call parent to avoid clashing axis/key names in concatenated result - return cat(A, parent(result); dims=append_dim) + # Conver result to Array to avoid clashing axis/key names in concatenated result + return cat(A, Array(result); dims=append_dim) end """ From bd8d4f9c2036ec6a9820c11c96b716faafea5e33 Mon Sep 17 00:00:00 2001 From: Glenn Moynihan Date: Thu, 1 Jul 2021 14:09:27 +0100 Subject: [PATCH 4/5] bump patch version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 5dec6c4..554f125 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "FeatureTransforms" uuid = "8fd68953-04b8-4117-ac19-158bf6de9782" authors = ["Invenia Technical Computing Corporation"] -version = "0.3.6" +version = "0.3.7" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" From cdb209a15c4393e4c761693f85b730424e2a9186 Mon Sep 17 00:00:00 2001 From: Glenn Moynihan Date: Thu, 1 Jul 2021 14:16:47 +0100 Subject: [PATCH 5/5] test on Reshaped and Sub arrays --- test/runtests.jl | 1 + test/types/matrix.jl | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 2e9dd36..c79833b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,6 @@ using AxisArrays using AxisKeys +using Base: ReshapedArray using DataFrames: DataFrame using Dates using Documenter: doctest diff --git a/test/types/matrix.jl b/test/types/matrix.jl index f4b3fed..3724eb1 100644 --- a/test/types/matrix.jl +++ b/test/types/matrix.jl @@ -1,6 +1,11 @@ -@testset "matrix" begin +# Want to test that certain subtypes of arrays are compatible +_make_matrix(::Type{Matrix}) = [1 2 3; 4 5 6] +_make_matrix(::Type{SubArray}) = view([1 2 3; 4 5 6], :, :) +_make_matrix(::Type{ReshapedArray}) = reshape([1 2 3; 4 5 6], 2, 3) - x = [1 2 3; 4 5 6] +@testset "$MatrixType" for MatrixType in (Matrix, SubArray, ReshapedArray) + + x = _make_matrix(MatrixType) @test is_transformable(x)