Skip to content

Commit

Permalink
Fix deprecation warnings related to types on Julia 0.6
Browse files Browse the repository at this point in the history
Use the new inner constructor and type alias syntax,
and get rid of type aliases needed for Julia 0.4.
  • Loading branch information
nalimilan committed Feb 17, 2017
1 parent 1113759 commit b974c39
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 33 deletions.
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
julia 0.5.0
Compat 0.17.0
Compat 0.18.0
NullableArrays
72 changes: 48 additions & 24 deletions src/typedefs.jl
Original file line number Diff line number Diff line change
@@ -1,25 +1,49 @@
typealias DefaultRefType UInt32
@compat const DefaultRefType = UInt32

## Pools

# V is always set to CategoricalValue{T}
# This workaround is needed since this type not defined yet
# See JuliaLang/julia#269
type CategoricalPool{T, R <: Integer, V}
index::Vector{T}
invindex::Dict{T, R}
order::Vector{R}
levels::Vector{T}
valindex::Vector{V}
ordered::Bool
if VERSION >= v"0.6.0-dev.2643"
include_string("""
type CategoricalPool{T, R <: Integer, V}
index::Vector{T}
invindex::Dict{T, R}
order::Vector{R}
levels::Vector{T}
valindex::Vector{V}
ordered::Bool
function CategoricalPool{T, R, V}(index::Vector{T},
invindex::Dict{T, R},
order::Vector{R},
ordered::Bool) where {T, R, V}
pool = new(index, invindex, order, index[order], V[], ordered)
buildvalues!(pool)
return pool
end
end
""")
else
@eval begin
type CategoricalPool{T, R <: Integer, V}
index::Vector{T}
invindex::Dict{T, R}
order::Vector{R}
levels::Vector{T}
valindex::Vector{V}
ordered::Bool

function CategoricalPool{T, R}(index::Vector{T},
invindex::Dict{T, R},
order::Vector{R},
ordered::Bool)
pool = new(index, invindex, order, index[order], V[], ordered)
buildvalues!(pool)
return pool
function CategoricalPool{T, R}(index::Vector{T},
invindex::Dict{T, R},
order::Vector{R},
ordered::Bool)
pool = new(index, invindex, order, index[order], V[], ordered)
buildvalues!(pool)
return pool
end
end
end
end

Expand All @@ -37,29 +61,29 @@ end
## Arrays

@compat abstract type AbstractCategoricalArray{T, N, R} <: AbstractArray{CategoricalValue{T, R}, N} end
typealias AbstractCategoricalVector{T, R} AbstractCategoricalArray{T, 1, R}
typealias AbstractCategoricalMatrix{T, R} AbstractCategoricalArray{T, 2, R}
@compat AbstractCategoricalVector{T, R} = AbstractCategoricalArray{T, 1, R}
@compat AbstractCategoricalMatrix{T, R} = AbstractCategoricalArray{T, 2, R}

immutable CategoricalArray{T, N, R <: Integer} <: AbstractCategoricalArray{T, N, R}
refs::Array{R, N}
pool::CategoricalPool{T, R, CategoricalValue{T, R}}
end
typealias CategoricalVector{T, R} CategoricalArray{T, 1, R}
typealias CategoricalMatrix{T, R} CategoricalArray{T, 2, R}
@compat CategoricalVector{T, R} = CategoricalArray{T, 1, R}
@compat CategoricalMatrix{T, R} = CategoricalArray{T, 2, R}

## Nullable Arrays

@compat abstract type AbstractNullableCategoricalArray{T, N, R} <: AbstractArray{Nullable{CategoricalValue{T, R}}, N} end
typealias AbstractNullableCategoricalVector{T, R} AbstractNullableCategoricalArray{T, 1, R}
typealias AbstractNullableCategoricalMatrix{T, R} AbstractNullableCategoricalArray{T, 2, R}
@compat AbstractNullableCategoricalVector{T, R} = AbstractNullableCategoricalArray{T, 1, R}
@compat AbstractNullableCategoricalMatrix{T, R} = AbstractNullableCategoricalArray{T, 2, R}

immutable NullableCategoricalArray{T, N, R <: Integer} <: AbstractNullableCategoricalArray{T, N, R}
refs::Array{R, N}
pool::CategoricalPool{T, R, CategoricalValue{T, R}}
end
typealias NullableCategoricalVector{T, R} NullableCategoricalArray{T, 1, R}
typealias NullableCategoricalMatrix{T, R} NullableCategoricalArray{T, 2, R}
@compat NullableCategoricalVector{T, R} = NullableCategoricalArray{T, 1, R}
@compat NullableCategoricalMatrix{T, R} = NullableCategoricalArray{T, 2, R}

## Type Aliases

typealias CatArray{T, N, R} Union{CategoricalArray{T, N, R}, NullableCategoricalArray{T, N, R}}
@compat CatArray{T, N, R} = Union{CategoricalArray{T, N, R}, NullableCategoricalArray{T, N, R}}
2 changes: 0 additions & 2 deletions test/03_constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ module TestConstructors
using CategoricalArrays: DefaultRefType
using Compat

typealias String Compat.ASCIIString

pool = CategoricalPool{String}()

@test isa(pool, CategoricalPool{String})
Expand Down
2 changes: 0 additions & 2 deletions test/11_array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ using CategoricalArrays
using CategoricalArrays: DefaultRefType
using Compat

typealias String Compat.ASCIIString

for ordered in (false, true)
for R in (CategoricalArrays.DefaultRefType, UInt8, UInt, Int8, Int)
# Vector
Expand Down
2 changes: 0 additions & 2 deletions test/12_nullablearray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ using NullableArrays
using CategoricalArrays: DefaultRefType
using Compat

typealias String Compat.ASCIIString

# == currently throws an error for Nullables
(==) = isequal

Expand Down
2 changes: 0 additions & 2 deletions test/13_arraycommon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ using NullableArrays
using CategoricalArrays: DefaultRefType
using Compat

typealias String Compat.ASCIIString

# == currently throws an error for Nullables
(==) = isequal

Expand Down

0 comments on commit b974c39

Please sign in to comment.