Skip to content

Commit

Permalink
fix some uses of missing and nothing
Browse files Browse the repository at this point in the history
  • Loading branch information
bjarthur committed Sep 11, 2018
1 parent 677f96a commit ecd940c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 59 deletions.
10 changes: 3 additions & 7 deletions src/aesthetics.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const NumericalOrCategoricalAesthetic =
Union{Nothing, Vector, Array, IndirectArray}
Union{Nothing, Vector, IndirectArray}

const CategoricalAesthetic =
Union{Nothing, IndirectArray}

const NumericalAesthetic =
Union{Nothing, Matrix, Vector, Array}
Union{Nothing, Matrix, Vector}


@varset Aesthetics begin
Expand Down Expand Up @@ -273,11 +273,7 @@ cat_aes_var!(a, b) = a

function cat_aes_var!(a::AbstractArray{T}, b::AbstractArray{U}) where {T, U}
V = promote_type(T, U)
if isa(a, Array{Union{Missing,T}}) || isa(b, Array{Union{Missing,U}})
ab = Array{Union{Missing,V}}(undef, length(a) + length(b))
else
ab = Array{V}(undef, length(a) + length(b))
end
ab = Array{V}(undef, length(a) + length(b))
i = 1
for x in a
ab[i] = x
Expand Down
5 changes: 1 addition & 4 deletions src/mapping.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ end

Base.hash(colgroup::GroupedColumn, h::UInt64) = hash(colgroup.columns, h)

function ==(a::GroupedColumn, b::GroupedColumn)
return (a.columns===nothing && b.columns===nothing) ||
(a.columns!==nothing && b.columns!==nothing && a.columns == b.columns)
end
==(a::GroupedColumn, b::GroupedColumn) = a.columns==b.columns

Base.show(io::IO, gc::GroupedColumn) = print(io, "Column")

Expand Down
50 changes: 3 additions & 47 deletions src/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,7 @@ end
function concrete_length(xs)
n = 0
for x in xs
if isconcrete(x)
n += 1
end
end
n
end

function concrete_length(xs::Array{Union{Missing,T}}) where T
n = 0
for i = 1:length(xs)
if !ismissing(xs[i]) && isconcrete(xs[i])
if !ismissing(x) && isconcrete(x)
n += 1
end
end
Expand Down Expand Up @@ -136,24 +126,7 @@ function concrete_minmax(xs, xmin::T, xmax::T) where T<:Real
end

for x in xs
if isconcrete(x)
xT = convert(T, x)
if isnan(xmin) || xT < xmin
xmin = xT
end
if isnan(xmax) || xT > xmax
xmax = xT
end
end
end
xmin, xmax
end


function concrete_minmax(xs::Array{Union{Missing,TA}}, xmin::T, xmax::T) where {T<:Real, TA}
for i = 1:length(xs)
if !ismissing(xs[i])
x = xs[i]
if !ismissing(x) && isconcrete(x)
xT = convert(T, x)
if isnan(xmin) || xT < xmin
xmin = xT
Expand All @@ -169,24 +142,7 @@ end

function concrete_minmax(xs, xmin::T, xmax::T) where T
for x in xs
if isconcrete(x)
xT = convert(T, x)
if xT < xmin
xmin = xT
end
if xT > xmax
xmax = xT
end
end
end
xmin, xmax
end


function concrete_minmax(xs::Array{Union{Missing,TA}}, xmin::T, xmax::T) where {T, TA}
for i = 1:length(xs)
if !ismissing(xs[i])
x = xs[i]
if !ismissing(x) && isconcrete(x)
xT = convert(T, x)
if xT < xmin
xmin = xT
Expand Down
2 changes: 1 addition & 1 deletion src/statistics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1428,7 +1428,7 @@ function apply_statistic(stat::FunctionStatistic,
if aes.color != nothing
func_color = aes.color
aes.color = Array{eltype(aes.color)}(undef, length(aes.y) * stat.num_samples)
groups = Array{Union{Missing,Int}}(undef, length(aes.y) * stat.num_samples)
groups = Array{Int}(undef, length(aes.y) * stat.num_samples)
for i in 1:length(aes.y)
aes.color[1+(i-1)*stat.num_samples:i*stat.num_samples] .= func_color[i]
groups[1+(i-1)*stat.num_samples:i*stat.num_samples] .= i
Expand Down

0 comments on commit ecd940c

Please sign in to comment.