From d67c6dae2cf083422260523ca1ed93bb2b6ec759 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 22 Aug 2020 06:41:39 +0000 Subject: [PATCH] Format files using DocumentFormat --- benchmark/array/reduce.jl | 72 +++++++++++++++++------------------ docs/make.jl | 10 ++--- examples/03-combined.jl | 2 +- src/array/constructors.jl | 2 +- src/array/datavaluevector.jl | 8 ++-- src/array/primitives.jl | 2 +- src/array/reduce.jl | 18 ++++----- src/scalar/core.jl | 4 +- src/scalar/operations.jl | 8 ++-- test/array/test_broadcast.jl | 12 +++--- test/array/test_primitives.jl | 18 ++++----- test/array/test_reduce.jl | 18 ++++----- test/array/test_subarray.jl | 6 +-- 13 files changed, 90 insertions(+), 90 deletions(-) diff --git a/benchmark/array/reduce.jl b/benchmark/array/reduce.jl index 38977a9..1f732a2 100644 --- a/benchmark/array/reduce.jl +++ b/benchmark/array/reduce.jl @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/docs/make.jl b/docs/make.jl index 4e78b43..7a1e06d 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -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") diff --git a/examples/03-combined.jl b/examples/03-combined.jl index 5fccd2b..ef78c1a 100644 --- a/examples/03-combined.jl +++ b/examples/03-combined.jl @@ -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 diff --git a/src/array/constructors.jl b/src/array/constructors.jl index d2bb979..0e7fac1 100644 --- a/src/array/constructors.jl +++ b/src/array/constructors.jl @@ -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} diff --git a/src/array/datavaluevector.jl b/src/array/datavaluevector.jl index 8d2c933..c8fbe3a 100644 --- a/src/array/datavaluevector.jl +++ b/src/array/datavaluevector.jl @@ -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 @@ -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 @@ -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) @@ -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 diff --git a/src/array/primitives.jl b/src/array/primitives.jl index 5cfc75d..3b338c4 100644 --- a/src/array/primitives.jl +++ b/src/array/primitives.jl @@ -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] diff --git a/src/array/reduce.jl b/src/array/reduce.jl index 89ba0e9..017c5c4 100644 --- a/src/array/reduce.jl +++ b/src/array/reduce.jl @@ -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 @@ -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 @@ -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 @@ -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}() @@ -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}() diff --git a/src/scalar/core.jl b/src/scalar/core.jl index d3e77ae..30c47f9 100644 --- a/src/scalar/core.jl +++ b/src/scalar/core.jl @@ -3,7 +3,7 @@ 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 @@ -11,7 +11,7 @@ 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{}}() diff --git a/src/scalar/operations.jl b/src/scalar/operations.jl index ae45cc3..0b27ba0 100644 --- a/src/scalar/operations.jl +++ b/src/scalar/operations.jl @@ -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)) diff --git a/test/array/test_broadcast.jl b/test/array/test_broadcast.jl index a87d517..0b67e74 100644 --- a/test/array/test_broadcast.jl +++ b/test/array/test_broadcast.jl @@ -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) diff --git a/test/array/test_primitives.jl b/test/array/test_primitives.jl index db55efc..49472b4 100644 --- a/test/array/test_primitives.jl +++ b/test/array/test_primitives.jl @@ -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 ------------------------------------------------------# @@ -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 --------------------------------------------------------# @@ -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) --------------------------------------------------# diff --git a/test/array/test_reduce.jl b/test/array/test_reduce.jl index 51a9c51..6f205e8 100644 --- a/test/array/test_reduce.jl +++ b/test/array/test_reduce.jl @@ -21,17 +21,17 @@ using Test M[j] = false X = DataValueArray(A) Y = DataValueArray(A, M) - B = A[findall(x->!x, M)] + B = A[findall(x -> !x, M)] @test isequal(mapreduce(f, +, X), DataValue(mapreduce(f, +, X.values))) @test isequal(mapreduce(f, +, Y), DataValue{Float64}()) - v = mapreduce(f, +, Y, skipna = true) + v = mapreduce(f, +, Y, skipna=true) @test v.value ≈ mapreduce(f, +, B) @test !isna(v) @test isequal(reduce(+, X), DataValue(reduce(+, X.values))) @test isequal(reduce(+, Y), DataValue{Float64}()) - v = reduce(+, Y, skipna = true) + v = reduce(+, Y, skipna=true) @test v.value ≈ reduce(+, B) @test !isna(v) @@ -42,18 +42,18 @@ using Test @test method(X) == DataValue(method(A)) @test method(f, X) == DataValue(method(f, A)) @test method(Y) == DataValue{Float64}() - v = method(Y, skipna = true) + v = method(Y, skipna=true) @test v.value ≈ method(B) @test !isna(v) @test method(f, Y) == DataValue{Float64}() - v = method(f, Y, skipna = true) + v = method(f, Y, skipna=true) @test v.value ≈ method(f, B) @test !isna(v) end @test isequal(extrema(X), (DataValue(minimum(A)), DataValue(maximum(A)))) @test isequal(extrema(Y), (DataValue{Float64}(), DataValue{Float64}())) - v1 = extrema(Y, skipna = true) + v1 = extrema(Y, skipna=true) v2 = extrema(B) @test v1[1].value == v2[1] @test !isna(v1[1]) @@ -61,7 +61,7 @@ using Test @test !isna(v1[2]) H = rand(Bool, N) - G = H[findall(x->!x, M)] + G = H[findall(x -> !x, M)] U = DataValueArray(H) V = DataValueArray(H, M) @@ -69,9 +69,9 @@ using Test |,) @test isequal(reduce(op, U), DataValue(reduce(op, H))) - @test isequal(reduce(op, U, skipna = true), + @test isequal(reduce(op, U, skipna=true), DataValue(reduce(op, H))) - @test isequal(reduce(op, V, skipna = true), + @test isequal(reduce(op, V, skipna=true), DataValue(reduce(op, G))) end end diff --git a/test/array/test_subarray.jl b/test/array/test_subarray.jl index 2efa285..26d4ec2 100644 --- a/test/array/test_subarray.jl +++ b/test/array/test_subarray.jl @@ -11,10 +11,10 @@ using DataValues H = [ rand(1:sz[i]) for i in 1:nd ] for i in 1:nd - J = [ (x->x == i ? I[x] : Colon())(j) for j in 1:nd ] + J = [ (x -> x == i ? I[x] : Colon())(j) for j in 1:nd ] S = view(X, J...) - H = [ (x->x == i ? I[x] : rand(1:sz[x]))(j) for j in 1:nd ] - _H = H[findall(x->x != i, collect(1:nd))] + H = [ (x -> x == i ? I[x] : rand(1:sz[x]))(j) for j in 1:nd ] + _H = H[findall(x -> x != i, collect(1:nd))] @test values(S, _H...) == X.values[H...] @test isna(S, _H...) == X.isna[H...]