Skip to content

Commit

Permalink
fix compare_equal crash when sizes don't match
Browse files Browse the repository at this point in the history
  • Loading branch information
bbejanov committed May 10, 2024
1 parent 7603163 commit c731e05
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/various.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export compare, @compare

@inline compare_equal(x, y; kwargs...) = isequal(x, y)
@inline compare_equal(x::Number, y::Number; atol=0, rtol=atol > 0 ? 0.0 : eps(), nans::Bool=false, kwargs...) = isapprox(x, y; atol, rtol, nans)
@inline compare_equal(x::AbstractArray{<:Number}, y::AbstractArray{<:Number}; atol=0, rtol=atol > 0 ? 0.0 : eps(), nans::Bool=false, kwargs...) = isapprox(x, y; atol, rtol, nans)
@inline compare_equal(x::AbstractArray{<:Number}, y::AbstractArray{<:Number}; atol=0, rtol=atol > 0 ? 0.0 : eps(), nans::Bool=false, kwargs...) = size(x) == size(y) && isapprox(x, y; atol, rtol, nans)
function compare_equal(x::TSeries, y::TSeries; ignoremissing=false, trange::Union{Nothing,AbstractUnitRange{<:MIT}}=nothing, atol=0, rtol=atol > 0 ? 0.0 : eps(), nans::Bool=false, kwargs...)
if frequencyof(x) != frequencyof(y)
return false
Expand Down
31 changes: 26 additions & 5 deletions test/test_various.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ end
@test (tv[tm] .= -1.0; tm == (tv .< 0.0))

@test (tv[tb] == tv.values[tb.values, :])
@test (tv[tb,:] == tv.values[tb.values, :])
@test (tv[tb, :] == tv.values[tb.values, :])
@test (tv[tb] = -1000 * ones(sum(tb), 3); sum(tv[tb]) == -1000 * 3 * sum(tb))
@test (tv[tb,:] = -2000 * ones(sum(tb), 3); sum(tv[tb]) == -2000 * 3 * sum(tb))
@test (tv[tb, :] = -2000 * ones(sum(tb), 3); sum(tv[tb]) == -2000 * 3 * sum(tb))
@test (tv[tb] .= -3000; sum(tv[tb]) == -3000 * 3 * sum(tb))
@test (tv[tb,:] .= -4000; sum(tv[tb]) == -4000 * 3 * sum(tb))
@test (tv[tb, :] .= -4000; sum(tv[tb]) == -4000 * 3 * sum(tb))


end
Expand Down Expand Up @@ -116,8 +116,8 @@ end
NaN 10.1 10.1 10.1 10.1]
@test isapprox(c, mat1, nans=true)
@test isapprox(mat1, c, nans=true)
@test isapprox(c.a, mat1[:,1], nans=true)
@test isapprox(mat1[:,1], c.a, nans=true)
@test isapprox(c.a, mat1[:, 1], nans=true)
@test isapprox(mat1[:, 1], c.a, nans=true)
d = overlay(b, a)
@test c isa MVTSeries
@test frequencyof(d) == frequencyof(b) == frequencyof(a)
Expand All @@ -139,3 +139,24 @@ end
10.1 10.1 10.1 10.1 NaN
10.1 10.1 10.1 10.1 NaN], nans=true)
end

@testset "misc" begin

o = ones(20, 3)
X = MVTSeries(2000Y, (:x, :y, :z), o)

@test parent(X) === o
@test parent(X.x) === view(o, :, 1)

@test transpose(X) === transpose(o)
@test transpose(X.x) === transpose(view(o, :, 1))

Z = MVTSeries(2000Y, (:x, :y, :z), ones(15, 3))

@test compare(X.values, Z.values, quiet=true) == false
@test compare(X, Z, quiet=true, ignoremissing=false) == false
@test compare(X, Z, quiet=true, ignoremissing=true) == true

@test Base.axes1(X) === axes(X,1)

end

0 comments on commit c731e05

Please sign in to comment.