Skip to content

Commit

Permalink
Handle set edge cases for Dimension/DimTuple args (#479)
Browse files Browse the repository at this point in the history
* Add breaking tests

* Repair broken tests

* Support set for DimTuple input

* Increment patch number

* Update test/set.jl
  • Loading branch information
sethaxen authored Apr 10, 2023
1 parent 4ce2294 commit d212562
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DimensionalData"
uuid = "0703355e-b756-11e9-17c0-8b28908087d0"
authors = ["Rafael Schouten <[email protected]>"]
version = "0.24.9"
version = "0.24.10"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
5 changes: 4 additions & 1 deletion src/Dimensions/set.jl
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/LookupArrays/set.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/set.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions test/set.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

2 comments on commit d212562

@sethaxen
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/81317

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.24.10 -m "<description of version>" d212562d2ec811cf7ac89ccda16d91db563a5c44
git push origin v0.24.10

Please sign in to comment.