Skip to content

Commit

Permalink
Merge 8b67769 into c7b3dd4
Browse files Browse the repository at this point in the history
  • Loading branch information
bkamins committed Jun 23, 2020
2 parents c7b3dd4 + 8b67769 commit 1f006c3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -964,3 +964,11 @@ function Base.sort!(v::CategoricalVector;

return v
end

Base.repeat(a::CatArrOrSub{T, N},
counts::Integer...) where {T, N} =
CategoricalArray{T, N}(repeat(refs(a), counts...), copy(pool(a)))

Base.repeat(a::CatArrOrSub{T, N};
inner = nothing, outer = nothing) where {T, N} =
CategoricalArray{T, N}(repeat(refs(a), inner=inner, outer=outer), copy(pool(a)))
22 changes: 22 additions & 0 deletions test/13_arraycommon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1803,4 +1803,26 @@ end
end
end

@testset "repeat" begin
for o in (false, true), c in (false, true), i in 0:2,
a in [["b", "a", "b"], ["b" "a"; "b" "c"],
[missing, "a", "b"], ["b" "a"; missing "c"]],
x in [categorical(a, ordered=o, compress=c),
view(categorical(a, ordered=o, compress=c), axes(a)...)]
xr = @inferred repeat(x, i)
@test which(repeat, (typeof(x), Int)).module == CategoricalArrays
@test typeof(parent(x)) == typeof(xr)
@test isordered(x) == isordered(xr)
@test xr categorical(repeat(a, i), ordered=o, compress=c)
for j in 0:2
ir = ntuple(x -> i, ndims(a))
or = ntuple(x -> j, ndims(a))
xr = @inferred repeat(x, inner=ir, outer=or)
@test typeof(parent(x)) == typeof(xr)
@test isordered(x) == isordered(xr)
@test xr categorical(repeat(a, inner=ir, outer=or), ordered=o, compress=c)
end
end
end

end

0 comments on commit 1f006c3

Please sign in to comment.