Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/array/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ Base.parent(A::AbstractDimArray) = data(A)
Base.vec(A::AbstractDimArray) = vec(parent(A))
# Only compare data and dim - metadata and refdims can be different
Base.:(==)(A1::AbstractDimArray, A2::AbstractDimArray) =
parent(A1) == parent(A2) && dims(A1) == dims(A2)

dims(A1) == dims(A2) && parent(A1) == parent(A2)
Base.isequal(A1::AbstractDimArray, A2::AbstractDimArray) =
isequal(dims(A1), dims(A2)) && isequal(parent(A1), parent(A2))
# undef constructor for Array, using dims
function Base.Array{T}(x::UndefInitializer, d1::Dimension, dims::Dimension...) where T
Base.Array{T}(x, (d1, dims...))
Expand Down
4 changes: 3 additions & 1 deletion src/stack/stack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ end
Base.parent(s::AbstractDimStack) = data(s)
# Only compare data and dim - metadata and refdims can be different
Base.:(==)(s1::AbstractDimStack, s2::AbstractDimStack) =
data(s1) == data(s2) && dims(s1) == dims(s2) && layerdims(s1) == layerdims(s2)
dims(s1) == dims(s2) && layerdims(s1) == layerdims(s2) && data(s1) == data(s2)
Base.isequal(s1::AbstractDimStack, s2::AbstractDimStack) =
isequal(dims(s1), dims(s2)) && isequal(layerdims(s1), layerdims(s2)) && isequal(data(s1), data(s2))
Base.read(s::AbstractDimStack) = maplayers(read, s)

# Array-like
Expand Down
17 changes: 17 additions & 0 deletions test/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -618,3 +618,20 @@ end
@test Base.dataids(a) == Base.dataids(parent(a))
@test Base.mightalias(a, parent(a))
end

@testset "isequal and == with missing" begin
a = [missing 0; 0 0]
ba = [missing 0 0; 0 0 0]

da = DimArray(a, (X(1:2), Y(1:2)))
dba = DimArray(ba, (X(1:2), Y(1:3)))

@test ismissing(dba[:,1:2] == da)
@test (dba == da) == false
@test isequal(dba, da) == false
@test isequal(dba[:,1:2], da)
@test isequal(da, dba[:,2:3]) == false
dshift = DimArray(a, (X(10:11), Y(2:3)))
@test isequal(da, dshift) == false
@test (da == dshift) == false
end
11 changes: 11 additions & 0 deletions test/stack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -384,4 +384,15 @@ end
@test ds[Z = 1] == (a = da1, b = da1)
@test ds[Z = 1:2] == ds

end

@testset "isequal and == with missing" begin
a = [missing 1; 1 1]
da1 = DimArray(a, (X(1:2), Y(1:2)))
da2 = DimArray(a, (X(2:3), Y(2:3)))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
da2 = DimArray(a, (X(2:3), Y(2:3)))
da2 = DimArray(copy(a), (X(2:3), Y(2:3)))

Just to make sure we don't hit any === fallbacks

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, should we use deepcopy?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think copy would be sufficient since a is just an array

ds1 = DimStack(da1)
ds2 = DimStack(da2)
@test (ds1 == ds2) == false
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know that this follows directly from the evaluation order, but somehow it feels a bit strange that this should return false and not missing? What do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this makes only sense to return false since this should also return false if the parent array is the same.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yea on second thought this is analogous to the changes to broadcast that I proposed where we should do dims checking before doing any calculations so I think this is the right way to go

@test ismissing(ds1 == ds1)
@test isequal(ds1, ds1)
end
Loading