Skip to content

Commit aa30eea

Browse files
ararslannalimilan
authored andcommitted
Julia 0.7 fixes (JuliaData#113)
* Workarounds for some stdlib moves * Use uninitialized in Array constructors * Wrap Nullable definitions in a VERSION check
1 parent df86ae9 commit aa30eea

27 files changed

+90
-55
lines changed

REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
julia 0.6
22
Missings
33
Reexport
4-
Compat 0.32.0
4+
Compat 0.39.0

src/CategoricalArrays.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ module CategoricalArrays
1515
using Reexport
1616
@reexport using Missings
1717

18+
if VERSION >= v"0.7.0-DEV.3052"
19+
using Printf
20+
end
21+
1822
include("typedefs.jl")
1923

2024
include("buildfields.jl")

src/array.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ Base.fill!(A::CategoricalArray, v::Any) =
340340

341341
function mergelevels(ordered, levels...)
342342
T = Base.promote_eltype(levels...)
343-
res = Array{T}(0)
343+
res = Array{T}(uninitialized, 0)
344344

345345
# Fast path in case all levels are equal
346346
if all(l -> l == levels[1], levels[2:end])

src/buildfields.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function buildindex(invindex::Dict{S, R}) where {S, R <: Integer}
2-
index = Vector{S}(length(invindex))
2+
index = Vector{S}(uninitialized, length(invindex))
33
for (v, i) in invindex
44
index[i] = v
55
end
@@ -37,6 +37,6 @@ function buildorder!(order::Array{R},
3737
end
3838

3939
function buildorder(invindex::Dict{S, R}, levels::Vector) where {S, R <: Integer}
40-
order = Vector{R}(length(invindex))
40+
order = Vector{R}(uninitialized, length(invindex))
4141
return buildorder!(order, invindex, levels)
4242
end

src/deprecated.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,13 @@
99
@deprecate CategoricalVector(::Type{T}, m::Integer; ordered=false) where {T} CategoricalVector{T}(m, ordered=ordered)
1010

1111
@deprecate CategoricalMatrix(::Type{T}, m::Int, n::Int; ordered=false) where {T} CategoricalMatrix{T}(m, n, ordered=ordered)
12+
13+
# Only define methods for Nullables while they're in Base, otherwise we don't care
14+
if VERSION < v"0.7.0-DEV.3017"
15+
Base.convert(::Type{Nullable{S}}, x::CategoricalValue{Nullable}) where {S} =
16+
convert(Nullable{S}, get(x))
17+
Base.convert(::Type{Nullable}, x::CategoricalValue{S}) where {S} = convert(Nullable{S}, x)
18+
Base.convert(::Type{Nullable{CategoricalValue{Nullable{T}}}},
19+
x::CategoricalValue{Nullable{T}}) where {T} =
20+
Nullable(x)
21+
end

src/extras.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function cut(x::AbstractArray{T, N}, breaks::AbstractVector;
7676
end
7777
end
7878

79-
refs = Array{DefaultRefType, N}(size(x))
79+
refs = Array{DefaultRefType, N}(uninitialized, size(x))
8080
try
8181
fill_refs!(refs, x, breaks, extend, allow_missing)
8282
catch err
@@ -93,7 +93,7 @@ function cut(x::AbstractArray{T, N}, breaks::AbstractVector;
9393
if isempty(labels)
9494
from = map(x -> sprint(showcompact, x), breaks[1:n-1])
9595
to = map(x -> sprint(showcompact, x), breaks[2:n])
96-
levs = Vector{String}(n-1)
96+
levs = Vector{String}(uninitialized, n-1)
9797
for i in 1:n-2
9898
levs[i] = string("[", from[i], ", ", to[i], ")")
9999
end

src/recode.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ function recode!(dest::CategoricalArray{T}, src::CategoricalArray, default::Any,
146146

147147
# Remove recoded levels as they won't appear in result
148148
firsts = (p.first for p in pairs)
149-
keptlevels = Vector{T}()
149+
keptlevels = Vector{T}(uninitialized, 0)
150150
sizehint!(keptlevels, length(srclevels))
151151

152152
for l in srclevels
@@ -177,7 +177,7 @@ function recode!(dest::CategoricalArray{T}, src::CategoricalArray, default::Any,
177177
srefs = src.refs
178178

179179
origmap = [get(dest.pool, v, 0) for v in srcindex]
180-
indexmap = Vector{DefaultRefType}(length(srcindex)+1)
180+
indexmap = Vector{DefaultRefType}(uninitialized, length(srcindex)+1)
181181
# For missing values (0 if no missing in pairs' keys)
182182
indexmap[1] = 0
183183
for p in pairs
@@ -343,7 +343,7 @@ function recode(a::AbstractArray, default::Any, pairs::Pair...)
343343
elseif T >: Missing || default === missing || (eltype(a) >: Missing && !keytype_hasmissing(pairs...))
344344
dest = Array{Union{T, Missing}}(size(a))
345345
else
346-
dest = Array{Missings.T(T)}(size(a))
346+
dest = Array{Missings.T(T)}(uninitialized, size(a))
347347
end
348348
recode!(dest, a, default, pairs...)
349349
end

src/value.jl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,6 @@ Base.promote_rule(::Type{C}, ::Type{T}) where {C <: CategoricalString, T <: Abst
5757
promote_type(leveltype(C), T)
5858
Base.promote_rule(::Type{C}, ::Type{Missing}) where {C <: CatValue} = Union{C, Missing}
5959

60-
Base.convert(::Type{Nullable{S}}, x::CategoricalValue{Nullable}) where {S} =
61-
convert(Nullable{S}, get(x))
62-
Base.convert(::Type{Nullable}, x::CategoricalValue{S}) where {S} = convert(Nullable{S}, x)
63-
Base.convert(::Type{Nullable{CategoricalValue{Nullable{T}}}},
64-
x::CategoricalValue{Nullable{T}}) where {T} =
65-
Nullable(x)
6660
Base.convert(::Type{Ref}, x::CatValue) = RefValue{leveltype(x)}(x)
6761
Base.convert(::Type{String}, x::CatValue) = convert(String, get(x))
6862
Base.convert(::Type{Any}, x::CatValue) = x

test/01_typedef.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module TestTypeDef
2-
using Base.Test
2+
using Compat
3+
using Compat.Test
34
using CategoricalArrays
45
using CategoricalArrays: DefaultRefType, level, reftype, leveltype, catvalue, iscatvalue
56

test/02_buildorder.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module TestUpdateOrder
2-
using Base.Test
2+
using Compat
3+
using Compat.Test
34
using CategoricalArrays
45
using CategoricalArrays: DefaultRefType
56

@@ -17,7 +18,7 @@ using CategoricalArrays: DefaultRefType
1718
)
1819
)
1920

20-
order = Vector{DefaultRefType}(length(pool.index))
21+
order = Vector{DefaultRefType}(uninitialized, length(pool.index))
2122

2223
CategoricalArrays.buildorder!(order, pool.invindex, ["b", "a", "c"])
2324

0 commit comments

Comments
 (0)