Skip to content

Commit

Permalink
Merge 2409d82 into 3c82f54
Browse files Browse the repository at this point in the history
  • Loading branch information
nalimilan committed Apr 15, 2020
2 parents 3c82f54 + 2409d82 commit b9ccf3f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
24 changes: 7 additions & 17 deletions src/array.jl
Expand Up @@ -765,23 +765,13 @@ since it needs to check whether levels are used or not.
"""
unique(A::CategoricalArray{T}) where {T} = _unique(T, A.refs, A.pool)

if VERSION >= v"0.7.0-DEV.4882"
"""
droplevels!(A::CategoricalArray)
Drop levels which do not appear in categorical array `A` (so that they will no longer be
returned by [`levels`](@ref)).
"""
droplevels!(A::CategoricalArray) = levels!(A, intersect!(levels(A), unique(A)))
else # intersect! method missing on Julia 0.6
"""
droplevels!(A::CategoricalArray)
Drop levels which do not appear in categorical array `A` (so that they will no longer be
returned by [`levels`](@ref)).
"""
droplevels!(A::CategoricalArray) = levels!(A, intersect(levels(A), filter!(!ismissing, unique(A))))
end
"""
droplevels!(A::CategoricalArray)
Drop levels which do not appear in categorical array `A` (so that they will no longer be
returned by [`levels`](@ref)).
"""
droplevels!(A::CategoricalArray) = levels!(A, intersect(levels(A), unique(A)))

"""
isordered(A::CategoricalArray)
Expand Down
3 changes: 3 additions & 0 deletions test/13_arraycommon.jl
Expand Up @@ -1377,6 +1377,9 @@ end
x[2] = "a"
@test droplevels!(x) === x
@test levels(x) == ["c", "a"]
x .= "a"
@test droplevels!(x) === x
@test levels(x) == ["a"]
end

@testset "show" begin
Expand Down

0 comments on commit b9ccf3f

Please sign in to comment.