Skip to content

Commit

Permalink
Add isordered for CategoricalValue (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
juliohm authored Mar 23, 2020
1 parent 92e3114 commit 81867f6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/value.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ reftype(x::Any) = reftype(typeof(x))

pool(x::CategoricalValue) = x.pool
level(x::CategoricalValue) = x.level
isordered(x::CategoricalValue) = isordered(x.pool)

# extract the type of the original value from array eltype `T`
unwrap_catvaluetype(::Type{T}) where {T} = T
Expand Down Expand Up @@ -177,4 +178,4 @@ JSON.lower(x::CategoricalValue) = JSON.lower(get(x))
DataAPI.defaultarray(::Type{CategoricalValue{T, R}}, N) where {T, R} =
CategoricalArray{T, N, R}
DataAPI.defaultarray(::Type{Union{CategoricalValue{T, R}, Missing}}, N) where {T, R} =
CategoricalArray{Union{T, Missing}, N, R}
CategoricalArray{Union{T, Missing}, N, R}
7 changes: 7 additions & 0 deletions test/10_isless.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ v2 = CategoricalValue(2, pool)
v3 = CategoricalValue(3, pool)

@testset "values from unordered CategoricalPool" begin
@test isordered(v1) === false
@test isordered(v2) === false
@test isordered(v3) === false

@test_throws ArgumentError v1 < v1
@test_throws ArgumentError v1 < v2
@test_throws ArgumentError v1 < v3
Expand Down Expand Up @@ -98,6 +102,9 @@ end
@testset "values from ordered CategoricalPool" begin
@test ordered!(pool, true) === pool
@test isordered(pool) === true
@test isordered(v1) === true
@test isordered(v2) === true
@test isordered(v3) === true

@test (v1 < v1) === false
@test (v1 < v2) === true
Expand Down

0 comments on commit 81867f6

Please sign in to comment.