Skip to content

Commit 0c57e8c

Browse files
committed
Preserve ordered property when converting CategoricalPool
This was not visible before since the convert() method for arrays explicitly called ordered!() even if it should not have been necessary.
1 parent 93c0fe4 commit 0c57e8c

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

src/array.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ for (A, V, M) in ((:CategoricalArray, :CategoricalVector, :CategoricalMatrix),
275275

276276
refs = convert(Array{R, N}, A.refs)
277277
pool = convert(CategoricalPool{T, R}, A.pool)
278-
ordered!($A(refs, pool), isordered(A))
278+
$A(refs, pool)
279279
end
280280
convert{S, T, N, R}(::Type{$A{T, N}}, A::CatArray{S, N, R}) =
281281
convert($A{T, N, R}, A)

src/pool.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function Base.convert{S, R}(::Type{CategoricalPool{S, R}}, pool::CategoricalPool
7272
indexS = convert(Vector{S}, pool.index)
7373
invindexS = convert(Dict{S, R}, pool.invindex)
7474
order = convert(Vector{R}, pool.order)
75-
return CategoricalPool(indexS, invindexS, order)
75+
return CategoricalPool(indexS, invindexS, order, pool.ordered)
7676
end
7777

7878
function Base.show{T, R}(io::IO, pool::CategoricalPool{T, R})

test/05_convert.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,8 @@ module TestConvert
2929
@test promote(1, v1) === (1, 1)
3030
@test promote(1.0, v1) === (1.0, 1.0)
3131
@test promote(0x1, v1) === (1, 1)
32+
33+
# Test that ordered property is preserved
34+
pool = CategoricalPool([1, 2, 3], true)
35+
@test convert(CategoricalPool{Float64, UInt8}, pool).ordered === true
3236
end

0 commit comments

Comments
 (0)