Skip to content

Commit

Permalink
Merge pull request #81 from queryverse/create-pull-request/patch
Browse files Browse the repository at this point in the history
[AUTO] Format files using DocumentFormat
  • Loading branch information
davidanthoff authored Aug 22, 2020
2 parents ace4e96 + d67c6da commit d568d25
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 90 deletions.
72 changes: 36 additions & 36 deletions benchmark/array/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,22 @@ function profile_reduce_methods()
prod,
minimum,
maximum,)
(method)(Y, skipnull = true)
(method)(Y, skipnull=true)
println("Method: $method(A) (~half missing entries, skip=true)")
print(" for NullableArray{Float64}: ")
@time((method)(Y, skipnull = true))
(method)(E, skipna = true)
@time((method)(Y, skipnull=true))
(method)(E, skipna=true)
print(" for DataArray{Float64}: ")
@time((method)(E, skipna = true))
@time((method)(E, skipna=true))
println()

(method)(f, Y, skipnull = true)
(method)(f, Y, skipnull=true)
println("Method: $method(f, A) (~half missing entries, skip=true)")
print(" for NullableArray{Float64}: ")
@time((method)(f, Y, skipnull = true))
(method)(f, E, skipna = true)
@time((method)(f, Y, skipnull=true))
(method)(f, E, skipna=true)
print(" for DataArray{Float64}: ")
@time((method)(f, E, skipna = true))
@time((method)(f, E, skipna=true))
println()
end

Expand Down Expand Up @@ -135,13 +135,13 @@ function profile_reduce_methods()

for method in (sumabs,
sumabs2)
(method)(Y, skipnull = true)
(method)(Y, skipnull=true)
println("Method: $method(A) (~half missing entries, skip=true)")
print(" for NullableArray{Float64}: ")
@time((method)(Y, skipnull = true))
(method)(E, skipna = true)
@time((method)(Y, skipnull=true))
(method)(E, skipna=true)
print(" for DataArray{Float64}: ")
@time((method)(E, skipna = true))
@time((method)(E, skipna=true))
println()
end
end
Expand Down Expand Up @@ -170,12 +170,12 @@ function profile_mapreduce(A, X, Y, D, E)
println()

println("Method: mapreduce(f, op, A) (~half missing entries, skip=true)")
mapreduce(f, Base.(:+), Y, skipnull = true)
mapreduce(f, Base.(:+), Y, skipnull=true)
print(" for NullableArray{Float64}: ")
@time(mapreduce(f, Base.(:+), Y, skipnull = true))
mapreduce(f, Base.(:+), E, skipna = true)
@time(mapreduce(f, Base.(:+), Y, skipnull=true))
mapreduce(f, Base.(:+), E, skipna=true)
print(" for DataArray{Float64}: ")
@time(mapreduce(f, Base.(:+), E, skipna = true))
@time(mapreduce(f, Base.(:+), E, skipna=true))
println()
end

Expand All @@ -202,12 +202,12 @@ function profile_reduce(A, X, Y, D, E)
println()

println("Method: reduce(f, op, A) (~half missing entries, skip=true)")
reduce(Base.(:+), Y, skipnull = true)
reduce(Base.(:+), Y, skipnull=true)
print(" for NullableArray{Float64}: ")
@time(reduce(Base.(:+), Y, skipnull = true))
reduce(Base.(:+), E, skipna = true)
@time(reduce(Base.(:+), Y, skipnull=true))
reduce(Base.(:+), E, skipna=true)
print(" for DataArray{Float64}: ")
@time(reduce(Base.(:+), E, skipna = true))
@time(reduce(Base.(:+), E, skipna=true))
println()
end

Expand All @@ -218,43 +218,43 @@ function profile_skip(skip::Bool)
println("f := identity, op := +")
println("mapreduce(f, op, X; skipnull/skipNA=$skip) (0 missing entries)")

mapreduce(identity, +, X, skipnull = skip)
mapreduce(identity, +, X, skipnull=skip)
print(" for NullableArray{Float64}: ")
@time(mapreduce(identity, +, X, skipnull = skip))
@time(mapreduce(identity, +, X, skipnull=skip))

mapreduce(identity, +, D, skipna = skip)
mapreduce(identity, +, D, skipna=skip)
print(" for DataArray{Float64}: ")
@time(mapreduce(identity, +, D, skipna = skip))
@time(mapreduce(identity, +, D, skipna=skip))

println()
println("reduce(op, X; skipnull/skipNA=$skip) (0 missing entries)")
reduce(+, X, skipnull = skip)
reduce(+, X, skipnull=skip)
print(" for NullableArray{Float64}: ")
@time(reduce(+, X, skipnull = skip))
@time(reduce(+, X, skipnull=skip))

reduce(+, D, skipna = skip)
reduce(+, D, skipna=skip)
print(" for DataArray{Float64}: ")
@time(reduce(+, D, skipna = skip))
@time(reduce(+, D, skipna=skip))

println()
println("mapreduce(f, op, X; skipnull/skipNA=$skip) (~half missing entries)")
mapreduce(identity, +, Y, skipnull = skip)
mapreduce(identity, +, Y, skipnull=skip)
print(" for NullableArray{Float64}: ")
@time(mapreduce(identity, +, Y, skipnull = skip))
@time(mapreduce(identity, +, Y, skipnull=skip))

mapreduce(identity, +, E, skipna = skip)
mapreduce(identity, +, E, skipna=skip)
print(" for DataArray{Float64}: ")
@time(mapreduce(identity, +, E, skipna = skip))
@time(mapreduce(identity, +, E, skipna=skip))

println()
println("reduce(op, X; skipnull/skipNA=$skip) (~half missing entries)")
reduce(+, Y, skipnull = skip)
reduce(+, Y, skipnull=skip)
print(" for NullableArray{Float64}: ")
@time(reduce(+, Y, skipnull = skip))
@time(reduce(+, Y, skipnull=skip))

reduce(+, E, skipna = true)
reduce(+, E, skipna=true)
print(" for DataArray{Float64}: ")
@time(reduce(+, E, skipna = true))
@time(reduce(+, E, skipna=true))
nothing
end

Expand Down
10 changes: 5 additions & 5 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Documenter, DataValues

makedocs(modules = [DataValues],
sitename = "DataValues.jl",
analytics = "UA-132838790-1",
pages = [
makedocs(modules=[DataValues],
sitename="DataValues.jl",
analytics="UA-132838790-1",
pages=[
"Introduction" => "index.md"
])

deploydocs(repo = "github.com/queryverse/DataValues.jl.git")
deploydocs(repo="github.com/queryverse/DataValues.jl.git")
2 changes: 1 addition & 1 deletion examples/03-combined.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ using DataValues

A = [DataValue(9), DataValue(8), DataValue(15)]

map(i->isna(i) ? false : get(i) % 3 == 0, A)
map(i -> isna(i) ? false : get(i) % 3 == 0, A)

f(i) = isna(i) ? false : get(i) % 3 == 0

Expand Down
2 changes: 1 addition & 1 deletion src/array/constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ end
# The following method allows for the construction of zero-element
# DataValueArrays by calling the parametrized type on zero arguments.
function DataValueArray{T,N}() where {T,N}
return DataValueArray{T}(ntuple(i->0, N))
return DataValueArray{T}(ntuple(i -> 0, N))
end

function DataValueArray{T,N}(data::AbstractArray{S,N}) where {S,T,N}
Expand Down
8 changes: 4 additions & 4 deletions src/array/datavaluevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Remove the item at index `i` and return the removed item. Subsequent items
are shifted down to fill the resulting gap. If specified, replacement values from
an ordered collection will be spliced in place of the removed item.
"""
function Base.splice!(X::DataValueVector, i::Integer, ins = _default_splice)
function Base.splice!(X::DataValueVector, i::Integer, ins=_default_splice)
v = X[i]
m = length(ins)
if m == 0
Expand Down Expand Up @@ -125,7 +125,7 @@ place of the removed items.
To insert `ins` before an index `n` without removing any items, use
`splice!(X, n:n-1, ins)`.
"""
function Base.splice!(X::DataValueVector, rng::UnitRange{T}, ins = _default_splice) where {T <: Integer}
function Base.splice!(X::DataValueVector, rng::UnitRange{T}, ins=_default_splice) where {T <: Integer}
vs = X[rng]
m = length(ins)
if m == 0
Expand Down Expand Up @@ -250,7 +250,7 @@ Modify `X` by reversing the first `n` elements starting at index `s`
(inclusive). If unspecified, `s` and `n` will default to `1` and `length(X)`,
respectively.
"""
function Base.reverse!(X::DataValueVector, s = 1, n = length(X))
function Base.reverse!(X::DataValueVector, s=1, n=length(X))
if isbitstype(eltype(X)) || !any(isna, X)
reverse!(X.values, s, n)
reverse!(X.isna, s, n)
Expand Down Expand Up @@ -280,7 +280,7 @@ Return a copy of `X` with the first `n` elements starting at index `s`
(inclusive) reversed. If unspecified, `s` and `n` will default to `1` and
`length(X)`, respectively.
"""
function Base.reverse(X::DataValueVector, s = 1, n = length(X))
function Base.reverse(X::DataValueVector, s=1, n=length(X))
return reverse!(copy(X), s, n)
end

Expand Down
2 changes: 1 addition & 1 deletion src/array/primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function dropna(X::AbstractVector{T}) where {T}
if !(DataValue <: T) && !(T <: DataValue)
return copy(X)
else
Y = filter(x->!isna(x), X)
Y = filter(x -> !isna(x), X)
res = similar(Y, eltype(T))
for i in eachindex(Y, res)
@inbounds res[i] = isa(Y[i], DataValue) ? Y[i].value : Y[i]
Expand Down
18 changes: 9 additions & 9 deletions src/array/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ behavior is enabled, `f` will be automatically lifted over the elements of `X`.
Note that, in general, mapreducing over a `DataValueArray` will return a
`DataValue` object regardless of whether `skipna` is set to `true` or `false`.
"""
function Base.mapreduce(f, op::Function, X::T; skipna::Bool = false) where {N,S <: DataValue,T <: AbstractArray{S,N}}
function Base.mapreduce(f, op::Function, X::T; skipna::Bool=false) where {N,S <: DataValue,T <: AbstractArray{S,N}}
if skipna
return DataValue(mapreduce(f, op, dropna(X)))
else
Expand All @@ -124,8 +124,8 @@ over the elements of `X`. Note that, in general, mapreducing over a
`DataValueArray` will return a `DataValue` object regardless of whether `skipna`
is set to `true` or `false`.
"""
function Base.reduce(op, X::T; skipna::Bool = false) where {N,S <: DataValue,T <: AbstractArray{S,N}}
return mapreduce(identity, op, X; skipna = skipna)
function Base.reduce(op, X::T; skipna::Bool=false) where {N,S <: DataValue,T <: AbstractArray{S,N}}
return mapreduce(identity, op, X; skipna=skipna)
end

# standard reductions
Expand All @@ -137,12 +137,12 @@ for (fn, op) in ((:(Base.sum), +),
@eval begin
# supertype(typeof(@functorize(abs))) returns Func{1} on Julia 0.4,
# and Function on 0.5
function $fn(f::Union{Function,Type}, X::T; skipna::Bool = false) where {N,S <: DataValue,T <: AbstractArray{S,N}}
return mapreduce(f, $op, X; skipna = skipna)
function $fn(f::Union{Function,Type}, X::T; skipna::Bool=false) where {N,S <: DataValue,T <: AbstractArray{S,N}}
return mapreduce(f, $op, X; skipna=skipna)
end

function $fn(X::T; skipna::Bool = false) where {N,S <: DataValue,T <: AbstractArray{S,N}}
return mapreduce(identity, $op, X; skipna = skipna)
function $fn(X::T; skipna::Bool=false) where {N,S <: DataValue,T <: AbstractArray{S,N}}
return mapreduce(identity, $op, X; skipna=skipna)
end
end
end
Expand Down Expand Up @@ -191,7 +191,7 @@ end
# return v
# end

function Base.extrema(X::T; skipna::Bool = false) where {N,T2,T <: DataValueArray{T2,N}}
function Base.extrema(X::T; skipna::Bool=false) where {N,T2,T <: DataValueArray{T2,N}}
length(X) > 0 || throw(ArgumentError("collection must be non-empty"))
vmin = DataValue{T2}()
vmax = DataValue{T2}()
Expand All @@ -213,7 +213,7 @@ function Base.extrema(X::T; skipna::Bool = false) where {N,T2,T <: DataValueArra
return (vmin, vmax)
end

function Base.extrema(X::T; skipna::Bool = false) where {N,T2,S <: DataValue{T2},T <: AbstractArray{S,N}}
function Base.extrema(X::T; skipna::Bool=false) where {N,T2,S <: DataValue{T2},T <: AbstractArray{S,N}}
length(X) > 0 || throw(ArgumentError("collection must be non-empty"))
vmin = DataValue{T2}()
vmax = DataValue{T2}()
Expand Down
4 changes: 2 additions & 2 deletions src/scalar/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ struct DataValue{T}
value::T

DataValue{T}() where {T} = new(false)
DataValue{T}(value::T, hasvalue::Bool = true) where {T} = new(hasvalue, value)
DataValue{T}(value::T, hasvalue::Bool=true) where {T} = new(hasvalue, value)
end

struct DataValueException <: Exception
end

const NA = DataValue{Union{}}()

DataValue(value::T, hasvalue::Bool = true) where {T} = DataValue{T}(value, hasvalue)
DataValue(value::T, hasvalue::Bool=true) where {T} = DataValue{T}(value, hasvalue)
DataValue(value::Missing) = DataValue{Union{}}()
DataValue{T}(::Missing) where T = DataValue{T}()
DataValue() = DataValue{Union{}}()
Expand Down
8 changes: 4 additions & 4 deletions src/scalar/operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ maptoTuple(f, a, b...) = Tuple{f(a),maptoTuple(f, b...).types...}
_nullable_eltype(f, A, As...) =
Base._return_type(f, maptoTuple(_unsafe_get_eltype, A, As...))

function Dates.DateTime(dt::DataValue{T}, format::AbstractString; locale::Dates.Locale = Dates.ENGLISH) where {T <: AbstractString}
isna(dt) ? DataValue{DateTime}() : DataValue{DateTime}(DateTime(unsafe_get(dt), format, locale = locale))
function Dates.DateTime(dt::DataValue{T}, format::AbstractString; locale::Dates.Locale=Dates.ENGLISH) where {T <: AbstractString}
isna(dt) ? DataValue{DateTime}() : DataValue{DateTime}(DateTime(unsafe_get(dt), format, locale=locale))
end

function Dates.Date(dt::DataValue{T}, format::AbstractString; locale::Dates.Locale = Dates.ENGLISH) where {T <: AbstractString}
isna(dt) ? DataValue{Date}() : DataValue{Date}(Date(unsafe_get(dt), format, locale = locale))
function Dates.Date(dt::DataValue{T}, format::AbstractString; locale::Dates.Locale=Dates.ENGLISH) where {T <: AbstractString}
isna(dt) ? DataValue{Date}() : DataValue{Date}(Date(unsafe_get(dt), format, locale=locale))
end

for f in (:(Base.abs), :(Base.abs2), :(Base.conj), :(Base.sign))
Expand Down
12 changes: 6 additions & 6 deletions test/array/test_broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ using Test
M3 = rand(Bool, 10, [dims; i]...)
C3 = Array{Float64}(undef, 10, [dims; i]...)

m1 = broadcast((x, y)->x, M1, M2)
m2 = broadcast((x, y)->x, M2, M3)
R2 = reshape(Bool[ (x->(m1[x] | M2[x]))(i) for i in 1:length(M2) ], size(M2))
R3 = reshape(Bool[ (x->(m2[x] | M3[x]))(i) for i in 1:length(M3) ], size(M3))
r2 = broadcast((x, y)->x, R2, R3)
Q3 = reshape(Bool[ (x->(r2[x] | R3[x]))(i) for i in 1:length(R3) ], size(M3))
m1 = broadcast((x, y) -> x, M1, M2)
m2 = broadcast((x, y) -> x, M2, M3)
R2 = reshape(Bool[ (x -> (m1[x] | M2[x]))(i) for i in 1:length(M2) ], size(M2))
R3 = reshape(Bool[ (x -> (m2[x] | M3[x]))(i) for i in 1:length(M3) ], size(M3))
r2 = broadcast((x, y) -> x, R2, R3)
Q3 = reshape(Bool[ (x -> (r2[x] | R3[x]))(i) for i in 1:length(R3) ], size(M3))

U1 = DataValueArray(A1)
U2 = DataValueArray(A2)
Expand Down
18 changes: 9 additions & 9 deletions test/array/test_primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,14 @@ using DataValues

Y1 = reshape(copy(Y), length(Y), 1)
@test size(Y1) == (length(Y), 1)
@test all(i->isequal(Y1[i], Y[i]), 1:length(Y))
@test all(i -> isequal(Y1[i], Y[i]), 1:length(Y))
Y2 = reshape(Y1, 1, length(Y1))
@test size(Y2) == (1, length(Y1))
@test all(i->isequal(Y1[i], Y2[i]), 1:length(Y2))
@test all(i -> isequal(Y1[i], Y2[i]), 1:length(Y2))
# Test that arrays share the same data
Y2.values[1] += 1
Y2.isna[2] = true
@test all(i->isequal(Y1[i], Y2[i]), 1:length(Y2))
@test all(i -> isequal(Y1[i], Y2[i]), 1:length(Y2))

# ----- test Base.ndims ------------------------------------------------------#

Expand All @@ -163,10 +163,10 @@ using DataValues
# ----- test Base.find -------------------------------------------------------#

z = DataValueArray(rand(Bool, 10))
@test (LinearIndices(z))[findall(x->x != 0, z)] == (LinearIndices(z.values))[findall(z.values)]
@test (LinearIndices(z))[findall(x -> x != 0, z)] == (LinearIndices(z.values))[findall(z.values)]

z = DataValueArray([false, true, false, true, false, true])
@test isequal((LinearIndices(z))[findall(x->x != 0, z)], [2, 4, 6])
@test isequal((LinearIndices(z))[findall(x -> x != 0, z)], [2, 4, 6])

# ----- test dropna --------------------------------------------------------#

Expand Down Expand Up @@ -207,11 +207,11 @@ using DataValues

# test that dropna! returns unwrapped values when DataValues are present
X = [false, 1, :c, "string", DataValue("I am not null"), DataValue()]
@test !any(x->isa(x, DataValue), dropna!(X))
@test any(x->isa(x, DataValue), X)
@test !any(x -> isa(x, DataValue), dropna!(X))
@test any(x -> isa(x, DataValue), X)
Y = Any[false, 1, :c, "string", DataValue("I am not null"), DataValue()]
@test !any(x->isa(x, DataValue), dropna!(Y))
@test any(x->isa(x, DataValue), Y)
@test !any(x -> isa(x, DataValue), dropna!(Y))
@test any(x -> isa(x, DataValue), Y)

# ----- test any(isna, X) --------------------------------------------------#

Expand Down
Loading

0 comments on commit d568d25

Please sign in to comment.