Skip to content

Conversation

@felixcremer
Copy link
Collaborator

This fixes the first half of #1107
This also adds a test for isequal which is currently broken because it goes into the fallback which doesn't take the dimensions into account.

This is the behaviour with this PR and a comparison to the base behaviour:

julia> a = [missing 1; 1 2]
2×2 Matrix{Union{Missing, Int64}}:
  missing  1
 1         2

julia> ba = [missing 1 3; 1 2 3]
2×3 Matrix{Union{Missing, Int64}}:
  missing  1  3
 1         2  3

julia> a == ba
false

julia> a == ba[:,1:2]
missing

julia> using DimensionalData
Precompiling DimensionalData finished.
  1 dependency successfully precompiled in 12 seconds. 28 already precompiled.

julia> da = DimArray(a, (X(1:2), Y(1:2)))
┌ 2×2 DimArray{Union{Missing, Int64}, 2} ┐
├────────────────────────────────────────┴───────── dims ┐
   X Sampled{Int64} 1:2 ForwardOrdered Regular Points,
   Y Sampled{Int64} 1:2 ForwardOrdered Regular Points
└────────────────────────────────────────────────────────┘
         

julia> dba = DimArray(ba, (X(1:2), Y(1:3)))
┌ 2×3 DimArray{Union{Missing, Int64}, 2} ┐
├────────────────────────────────────────┴───────── dims ┐
   X Sampled{Int64} 1:2 ForwardOrdered Regular Points,
   Y Sampled{Int64} 1:3 ForwardOrdered Regular Points
└────────────────────────────────────────────────────────┘
         

julia> dba == da
false

julia> dba[:,1:2] == da
missing

julia> dba == da
``

@tiemvanderdeure
Copy link
Collaborator

Can you add a similar change for dimstacks?

@felixcremer
Copy link
Collaborator Author

I added the same change also for DimStacks and also added some tests for it.

@felixcremer
Copy link
Collaborator Author

This now also fixes isequal by calling isequal on the dims and parent and layerdims for DimStack.

@codecov
Copy link

codecov bot commented Oct 10, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.91%. Comparing base (3a8c363) to head (0331787).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1111   +/-   ##
=======================================
  Coverage   86.90%   86.91%           
=======================================
  Files          55       55           
  Lines        5338     5340    +2     
=======================================
+ Hits         4639     4641    +2     
  Misses        699      699           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

da2 = DimArray(a, (X(2:3), Y(2:3)))
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

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants