Skip to content

Commit

Permalink
Deprecate A(T, dims) constructors
Browse files Browse the repository at this point in the history
These have been deprecated in Julia too and have simple replacements.
  • Loading branch information
nalimilan committed Feb 12, 2017
1 parent 40dbe3d commit e2f65c6
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 42 deletions.
13 changes: 0 additions & 13 deletions src/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,8 @@ for (A, V, M) in ((:CategoricalArray, :CategoricalVector, :CategoricalMatrix),

# Uninitialized array constructors

$A{T, N}(::Type{T}, dims::NTuple{N,Int}; ordered=false) =
$A(zeros(DefaultRefType, dims), CategoricalPool{T}(ordered))
$A{T}(::Type{T}, dims::Int...; ordered=false) = ordered!($A{T}(dims), ordered)
$A(dims::Int...; ordered=false) = $A{String}(dims, ordered=ordered)

$A{T, N, R}(::Type{CategoricalValue{T, R}}, dims::NTuple{N,Int}) = $A{T, N, R}(dims)
$A{T, N}(::Type{CategoricalValue{T}}, dims::NTuple{N,Int}) = $A{T, N}(dims)
# $A{N}(::Type{CategoricalValue}, dims::NTuple{N,Int}) = $A{String, N}(dims)

@compat (::Type{$A{T, N, R}}){T, N, R}(dims::NTuple{N,Int}; ordered=false) =
$A{T, N, R}(zeros(R, dims), CategoricalPool{T, R}(ordered))
@compat (::Type{$A{T, N}}){T, N}(dims::NTuple{N,Int}; ordered=false) =
Expand Down Expand Up @@ -185,16 +178,10 @@ for (A, V, M) in ((:CategoricalArray, :CategoricalVector, :CategoricalMatrix),
# ordered=false) =
# $A{String, N}(dims, ordered=ordered)

if VERSION >= v"0.5.0-dev"
$V{T}(::Type{T}, m::Integer; ordered=false) = $A{T}((m,), ordered=ordered)
$V(m::Integer; ordered=false) = $A(m, ordered=ordered)
end
@compat (::Type{$V{T}}){T}(m::Int; ordered=false) = $A{T}((m,), ordered=ordered)

if VERSION >= v"0.5.0-dev"
$M{T}(::Type{T}, m::Int, n::Int; ordered=false) = $A{T}((m, n), ordered=ordered)
$M(m::Int, n::Int; ordered=false) = $A(m, n, ordered=ordered)
end
@compat (::Type{$M{T}}){T}(m::Int, n::Int; ordered=false) = $A{T}((m, n), ordered=ordered)


Expand Down
12 changes: 12 additions & 0 deletions src/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,15 @@

@deprecate compact compress
@deprecate uncompact decompress

@deprecate CategoricalArray{T, N}(::Type{T}, dims::NTuple{N,Int}; ordered=false) CategoricalArray{T}(dims, ordered=ordered)
@deprecate CategoricalArray{T}(::Type{T}, dims::Int...; ordered=false) CategoricalArray{T}(dims, ordered=ordered)

@deprecate NullableCategoricalArray{T, N}(::Type{T}, dims::NTuple{N,Int}; ordered=false) NullableCategoricalArray{T}(dims, ordered=ordered)
@deprecate NullableCategoricalArray{T}(::Type{T}, dims::Int...; ordered=false) NullableCategoricalArray{T}(dims, ordered=ordered)

@deprecate CategoricalVector{T}(::Type{T}, m::Integer; ordered=false) CategoricalVector{T}(m, ordered=ordered)
@deprecate NullableCategoricalVector{T}(::Type{T}, m::Integer; ordered=false) NullableCategoricalVector{T}(m, ordered=ordered)

@deprecate CategoricalMatrix{T}(::Type{T}, m::Int, n::Int; ordered=false) CategoricalMatrix{T}(m, n, ordered=ordered)
@deprecate NullableCategoricalMatrix{T}(::Type{T}, m::Int, n::Int; ordered=false) NullableCategoricalMatrix{T}(m, n, ordered=ordered)
9 changes: 0 additions & 9 deletions src/nullablearray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,8 @@ NullableCategoricalArray{T}(::Type{Nullable{T}}, dims::Int...; ordered=false) =
# ordered=false) =
# NullableCategoricalArray{String, N}(dims; ordered=ordered)

if VERSION >= v"0.5.0-dev"
NullableCategoricalVector{T}(::Type{Nullable{T}}, m::Integer; ordered=false) =
NullableCategoricalArray{T}((m,); ordered=ordered)
end
@compat (::Type{NullableCategoricalVector{Nullable{T}}}){T}(m::Int; ordered=false) =
NullableCategoricalArray{T}((n,); ordered=ordered)

if VERSION >= v"0.5.0-dev"
NullableCategoricalMatrix{T}(::Type{Nullable{T}}, m::Int, n::Int; ordered=false) =
NullableCategoricalArray{T}((m, n); ordered=ordered)
end
@compat (::Type{NullableCategoricalMatrix{Nullable{T}}}){T}(m::Int, n::Int; ordered=false) =
NullableCategoricalArray{T}((m, n); ordered=ordered)

Expand Down
12 changes: 2 additions & 10 deletions test/11_array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -603,28 +603,20 @@ for ordered in (false, true)

# Uninitialized array
v = Any[CategoricalArray(2, ordered=ordered),
CategoricalArray(String, 2, ordered=ordered),
CategoricalArray{String}(2, ordered=ordered),
CategoricalArray{String, 1}(2, ordered=ordered),
CategoricalArray{String, 1, R}(2, ordered=ordered),
CategoricalVector(2, ordered=ordered),
CategoricalVector{String}(2, ordered=ordered),
CategoricalVector{String, R}(2, ordered=ordered),
CategoricalArray(2, 3, ordered=ordered),
CategoricalArray(String, 2, 3, ordered=ordered),
CategoricalArray{String}(2, 3, ordered=ordered),
CategoricalArray{String, 2}(2, 3, ordered=ordered),
CategoricalArray{String, 2, R}(2, 3, ordered=ordered),
CategoricalMatrix(2, 3, ordered=ordered),
CategoricalMatrix{String}(2, 3, ordered=ordered),
CategoricalMatrix{String, R}(2, 3, ordered=ordered)]

# See conditional definition of constructors in array.jl
if VERSION >= v"0.5.0-dev"
push!(v, CategoricalVector(2, ordered=ordered),
CategoricalVector(String, 2, ordered=ordered),
CategoricalMatrix(2, 3, ordered=ordered),
CategoricalMatrix(String, 2, 3, ordered=ordered))
end

for x in v
@test !isassigned(x, 1) && isdefined(x, 1)
@test !isassigned(x, 2) && isdefined(x, 2)
Expand Down
12 changes: 2 additions & 10 deletions test/12_nullablearray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1022,28 +1022,20 @@ for ordered in (false, true)

# Uninitialized array
v = Any[NullableCategoricalArray(2, ordered=ordered),
NullableCategoricalArray(String, 2, ordered=ordered),
NullableCategoricalArray{String}(2, ordered=ordered),
NullableCategoricalArray{String, 1}(2, ordered=ordered),
NullableCategoricalArray{String, 1, R}(2, ordered=ordered),
NullableCategoricalVector(2, ordered=ordered),
NullableCategoricalVector{String}(2, ordered=ordered),
NullableCategoricalVector{String, R}(2, ordered=ordered),
NullableCategoricalArray(2, 3, ordered=ordered),
NullableCategoricalArray(String, 2, 3, ordered=ordered),
NullableCategoricalArray{String}(2, 3, ordered=ordered),
NullableCategoricalArray{String, 2}(2, 3, ordered=ordered),
NullableCategoricalArray{String, 2, R}(2, 3, ordered=ordered),
NullableCategoricalMatrix(2, 3, ordered=ordered),
NullableCategoricalMatrix{String}(2, 3, ordered=ordered),
NullableCategoricalMatrix{String, R}(2, 3, ordered=ordered)]

# See conditional definition of constructors in array.jl and nullablearray.jl
if VERSION >= v"0.5.0-dev"
push!(v, NullableCategoricalVector(2, ordered=ordered),
NullableCategoricalVector(String, 2, ordered=ordered),
NullableCategoricalMatrix(2, 3, ordered=ordered),
NullableCategoricalMatrix(String, 2, 3, ordered=ordered))
end

for x in v
@test isordered(x) === ordered
@test isnull(x[1])
Expand Down

0 comments on commit e2f65c6

Please sign in to comment.