Skip to content
This repository has been archived by the owner on May 4, 2019. It is now read-only.

Commit

Permalink
Support empty literals
Browse files Browse the repository at this point in the history
  • Loading branch information
simonster committed Jul 2, 2014
1 parent 140a526 commit 695c21c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/literals.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function fixargs(args::Vector{Any}, stub::Any)
n = length(args)
data = Array(Any, n)
na = Array(Any, n)
na = BitArray(n)
for i in 1:n
if args[i] == :NA
data[i] = stub
Expand Down Expand Up @@ -47,12 +47,11 @@ end
function parsevector(ex::Expr)
if ex.head in (:ref, :typed_hcat, :typed_vcat)
data, na = fixargs(ex.args[2:end], :(zero($(ex.args[1]))))
return Expr(ex.head, ex.args[1], data...),
Expr(ex.head == :typed_hcat ? :hcat : :vcat, na...)
return Expr(ex.head, ex.args[1], data...), ex.head == :typed_hcat ? na' : na
else
stub = findstub_vector(ex)
data, na = fixargs(ex.args, stub)
return Expr(ex.head, data...), Expr(ex.head, na...)
return Expr(ex.head, data...), ex.head == :hcat ? na' : na
end
end

Expand Down
8 changes: 8 additions & 0 deletions test/literals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ module TestLiterals
using Base.Test
using DataArrays

dv = @data []
@test isequal(dv, DataArray([], Bool[]))
@test typeof(dv) == DataVector{None}

dv = @data Float64[]
@test isequal(dv, DataArray(Float64[], Bool[]))
@test typeof(dv) == DataVector{Float64}

dv = @data [1, NA, 3]
@test isequal(dv,
DataArray([1, 0, 3],
Expand Down

0 comments on commit 695c21c

Please sign in to comment.