Skip to content

Commit

Permalink
Merge b50fb4a into 8044adf
Browse files Browse the repository at this point in the history
  • Loading branch information
nalimilan committed Apr 9, 2020
2 parents 8044adf + b50fb4a commit 939aa57
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/array.jl
Expand Up @@ -383,6 +383,13 @@ end
@inbounds A.refs[I...] = get!(A.pool, v)
end

Base.fill(v::CategoricalValue{T}, dims::NTuple{N, Integer}) where {T, N} =
CategoricalArray{T, N}(fill(level(v), dims), copy(pool(v)))

# to avoid ambiguity
Base.fill(v::CategoricalValue, dims::Tuple{}) =
invoke(fill, Tuple{CategoricalValue{T}, NTuple{N, Integer}} where {T, N}, v, dims)

function Base.fill!(A::CategoricalArray, v::Any)
# TODO: use a global table to cache subset relations for all pairs of pools
if v isa CategoricalValue && pool(v) !== pool(A) && pool(v) pool(A)
Expand Down
14 changes: 14 additions & 0 deletions test/13_arraycommon.jl
Expand Up @@ -1652,4 +1652,18 @@ end
@test levelcode.(x) isa Vector{Union{Missing,Int16}}
end

@testset "fill()" begin
for ordered in (false, true), dims in ([1], [(1,)], [2, 3], [(2, 3)], [], [()])
x = CategoricalArray{String, 1, UInt8}(["a", "b", "c"],
ordered=ordered)

y = fill(x[1], dims...)
yref = fill("a", dims...)
@test y == yref
@test y isa CategoricalArray{String, ndims(yref), UInt8}
@test levels(y) == levels(x)
@test isordered(y) === isordered(x)
end
end

end

0 comments on commit 939aa57

Please sign in to comment.