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

WIP: support NullableArrays conversions if #undef values are null #79

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,25 @@ function Base.convert(::Type{NullableArray},
return NullableArray(A)
end

function Base.convert{S, T, N}(::Type{NullableArray{S}},
X::NullableArray{T, N}) # -> NullableArray{S, N}
res = similar(X, Nullable{S}, size(X))
for i in eachindex(X)
if !isassigned(X.values, i)
X.isnull[i] ? nothing : error()
else
res[i] = X[i]
end
end
return res
end

function Base.convert{S, T, N}(::Type{NullableArray{S, N}},
A::NullableArray{T, N}) # -> NullableArray{S, N}
return NullableArray(convert(Array{S}, A.values), A.isnull)
X::NullableArray{T, N}) # -> NullableArray{S, N}
res = NullableArray(convert(Array{S}, X.values), X.isnull)
# res2 = convert(NullableArray{S}, X)
# println(isequal(res, res2))
return res
end

@doc """
Expand Down
2 changes: 1 addition & 1 deletion src/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ for (fn, op) in ((:(Base.sum), Base.AddFun()),
(:(Base.minimum), Base.MinFun()),
(:(Base.maximum), Base.MaxFun()))
@eval begin
$fn(f::Union(Function,Base.Func{1}),
$fn(f::Union{Function,Base.Func{1}},
X::NullableArray;
skipnull::Bool = false) =
mapreduce(f, $op, X; skipnull = skipnull)
Expand Down