Skip to content

Commit

Permalink
Fix convert(::Type{Any}, ::CategoricalValue) on Julia 0.7
Browse files Browse the repository at this point in the history
Method ambiguity triggered a test failure in DataTables when working
with CategoricalArray{Any}.
  • Loading branch information
nalimilan committed Jun 22, 2017
1 parent 18f088f commit 15ab16f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/value.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ function CategoricalValue{T, R}(level::Integer, pool::CategoricalPool{T, R})
return CategoricalValue(convert(R, level), pool)
end

Base.convert{T, R}(::Type{CategoricalValue{T, R}}, x::CategoricalValue{T, R}) = x
Base.convert{T, R <: Integer}(::Type{CategoricalValue{T, R}}, x::CategoricalValue{T, R}) = x
Base.convert{T}(::Type{CategoricalValue{T}}, x::CategoricalValue{T}) = x
Base.convert(::Type{CategoricalValue}, x::CategoricalValue) = x

Expand All @@ -18,8 +18,9 @@ Base.convert{T}(::Type{Nullable{CategoricalValue{Nullable{T}}}},
x::CategoricalValue{Nullable{T}}) =
Nullable(x)
Base.convert{T}(::Type{Ref}, x::CategoricalValue{T}) = RefValue{T}(x)
Base.convert(::Type{Any}, x::CategoricalArrays.CategoricalValue) = x

Base.convert{S, T, R}(::Type{S}, x::CategoricalValue{T, R}) = convert(S, index(x.pool)[x.level])
Base.convert{S}(::Type{S}, x::CategoricalValue) = convert(S, index(x.pool)[x.level])

function Base.show{T}(io::IO, x::CategoricalValue{T})
if @compat(get(io, :compact, false))
Expand Down
17 changes: 11 additions & 6 deletions test/05_convert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ module TestConvert
v2 = CategoricalValue(2, pool)
v3 = CategoricalValue(3, pool)

convert(Int32, v1)
convert(Int32, v2)
convert(Int32, v3)
@test convert(Int32, v1) === Int32(1)
@test convert(Int32, v2) === Int32(2)
@test convert(Int32, v3) === Int32(3)

convert(UInt8, v1)
convert(UInt8, v2)
convert(UInt8, v3)
@test convert(UInt8, v1) === 0x01
@test convert(UInt8, v2) === 0x02
@test convert(UInt8, v3) === 0x03

@test convert(CategoricalValue, v1) === v1
@test convert(CategoricalValue{Int}, v1) === v1
@test convert(CategoricalValue{Int, CategoricalArrays.DefaultRefType}, v1) === v1
@test convert(Any, v1) === v1

@test get(v1) === 1
@test get(v2) === 2
Expand Down

0 comments on commit 15ab16f

Please sign in to comment.