diff --git a/Project.toml b/Project.toml index 124578f1a..eb07547ac 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "DimensionalData" uuid = "0703355e-b756-11e9-17c0-8b28908087d0" authors = ["Rafael Schouten "] -version = "0.24.9" +version = "0.24.10" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" diff --git a/src/Dimensions/set.jl b/src/Dimensions/set.jl index 244c83941..cfb5de80f 100644 --- a/src/Dimensions/set.jl +++ b/src/Dimensions/set.jl @@ -1,6 +1,8 @@ const DimSetters = Union{LookupArraySetters,Type,UnionAll,Dimension,Symbol} set(dim::Dimension, x::DimSetters) = _set(dim, x) +set(dims_::DimTuple, args::Union{Dimension,DimTuple,Pair}...; kw...) = + _set(dims_, args...; kw...) # Convert args/kw to dims and set _set(dims_::DimTuple, args::Dimension...; kw...) = _set(dims_, (args..., kwdims(kw)...)) # Convert pairs to wrapped dims and set @@ -19,7 +21,8 @@ _set(dims::DimTuple, wrappers::DimTuple) = begin end # Set things wrapped in dims -_set(dim::Dimension, wrapper::Dimension{<:DimSetters}) = _set(dim::Dimension, val(wrapper)) +_set(dim::Dimension, wrapper::Dimension{<:DimSetters}) = + _set(_set(dim, basetypeof(wrapper)), val(wrapper)) # Set the dim, checking the lookup _set(dim::Dimension, newdim::Dimension) = _set(newdim, _set(val(dim), val(newdim))) # Construct types diff --git a/src/LookupArrays/set.jl b/src/LookupArrays/set.jl index 9c12c8a0a..54a8e33d1 100644 --- a/src/LookupArrays/set.jl +++ b/src/LookupArrays/set.jl @@ -91,7 +91,9 @@ _set(metadata::AllMetadata, newmetadata::AllMetadata) = newmetadata # Index _set(index::AbstractArray, newindex::AbstractArray) = newindex _set(index::AbstractArray, newindex::AutoLookup) = index +_set(index::AbstractArray, newindex::Colon) = index _set(index::Colon, newindex::AbstractArray) = newindex +_set(index::Colon, newindex::Colon) = index _set(A, x) = _cantseterror(A, x) diff --git a/src/set.jl b/src/set.jl index df4092e60..6f2319a19 100644 --- a/src/set.jl +++ b/src/set.jl @@ -107,7 +107,7 @@ set(A::AbstractDimStack, x::LookupArray) = LookupArrays._cantseterror(A, x) set(A::AbstractDimArray, x::LookupArray) = LookupArrays._cantseterror(A, x) set(A, x) = LookupArrays._cantseterror(A, x) set(A::DimArrayOrStack, args::Union{Dimension,DimTuple,Pair}...; kw...) = - rebuild(A, data(A), _set(dims(A), args...; kw...)) + rebuild(A, data(A), set(dims(A), args...; kw...)) set(A::AbstractDimArray, newdata::AbstractArray) = begin axes(A) == axes(newdata) || _axiserr(A, newdata) rebuild(A; data=newdata) diff --git a/test/set.jl b/test/set.jl index c70422371..0a16d270b 100644 --- a/test/set.jl +++ b/test/set.jl @@ -112,6 +112,19 @@ end @test order(set(uda, X=ReverseOrdered())) == (ReverseOrdered(), Unordered()) end + # issue #478 + @testset "tuple dims and/or Symbol/Dim{Colon}/Colon replacement" begin + @test set(Dim{:foo}(), :bar) === Dim{:bar}() + @test set(Dim{:foo}(2:11), :bar) === Dim{:bar}(2:11) + @test set(Dim{:foo}(), Dim{:bar}()) === Dim{:bar}() + @test set(Dim{:foo}(2:11), Dim{:bar}()) === Dim{:bar}(2:11) + @test set(Dim{:foo}(LookupArrays.Sampled(2:11)), Dim{:bar}(LookupArrays.Sampled(0:9))) === + set(set(Dim{:foo}(LookupArrays.Sampled(2:11)), :bar), LookupArrays.Sampled(0:9)) + @test set((Dim{:foo}(),), :foo => :bar) === (Dim{:bar}(),) + @test set((Dim{:foo}(2:11),), :foo => :bar) === (Dim{:bar}(2:11),) + @test set(dimz, :X => :foo, :Y => :bar) === + (set(dims(dimz, :X), :foo), set(dims(dimz, :Y), :bar)) + end end @testset "metadata" begin