Skip to content

Commit 9aeb742

Browse files
authored
Drop redundant convert(Union{T, Missing/Nothing}, x) methods (#396)
The fallback defined in Base calls `convert(T, x)`, giving the same result, and these methods cause invalidations. Add tests as these were missing.
1 parent 847a745 commit 9aeb742

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/value.jl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,9 @@ Base.promote_rule(::Type{C1}, ::Type{C2}) where
8888
Base.promote_rule(::Type{C1}, ::Type{C2}) where {C1<:CategoricalValue, C2<:CategoricalValue} =
8989
CategoricalValue{cat_promote_type(leveltype(C1), leveltype(C2))}
9090

91-
# General fallbacks
91+
# General fallback
9292
Base.convert(::Type{S}, x::CategoricalValue) where {S <: SupportedTypes} =
9393
convert(S, unwrap(x))
94-
Base.convert(::Type{Union{S, Missing}}, x::CategoricalValue) where {S <: SupportedTypes} =
95-
convert(Union{S, Missing}, unwrap(x))
96-
Base.convert(::Type{Union{S, Nothing}}, x::CategoricalValue) where {S <: SupportedTypes} =
97-
convert(Union{S, Nothing}, unwrap(x))
9894

9995
(::Type{T})(x::T) where {T <: CategoricalValue} = x
10096

test/05_convert.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ using CategoricalArrays: DefaultRefType, refcode, reftype, leveltype
4949
@test convert(Union{T, U}, v3) === v3
5050
end
5151

52+
for T in (Int, Int8, Float64), U in (Missing, Nothing)
53+
@test convert(Union{T, U}, v1)::T == v1
54+
@test convert(Union{T, U}, v2)::T == v2
55+
@test convert(Union{T, U}, v3)::T == v3
56+
end
57+
5258
@test unwrap(v1) === get(v1) === 1
5359
@test unwrap(v2) === get(v2) === 2
5460
@test unwrap(v3) === get(v3) === 3

0 commit comments

Comments
 (0)