Skip to content

Commit

Permalink
drop missings dep (#26)
Browse files Browse the repository at this point in the history
* drop missings dep

* eliminate Missings
  • Loading branch information
Pietro Vertechi authored Sep 6, 2018
1 parent 31d01dc commit e2bfc02
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 32 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Use `copy` to collect the shifted data into an `Array`:

```julia
julia> copy(s)
4×4 Array{Union{Int64, Missings.Missing},2}:
4×4 Array{Union{Int64, Missing},2}:
missing missing missing missing
missing missing missing missing
1 5 9 13
Expand Down Expand Up @@ -184,9 +184,9 @@ Then we should first compute the list of `ShiftedArrays`:
```julia
julia> ss = ShiftedArray.((data,), .-times) # You need to subtract the index to center around times
3-element Array{ShiftedArrays.ShiftedArray{Int64,1,Array{Int64,1}},1}:
Union{Int64, Missings.Missing}[5, 6, 7, 9, 16, 2, 3, 4, 7, missing, missing]
Union{Int64, Missings.Missing}[2, 3, 4, 7, missing, missing, missing, missing, missing, missing, missing]
Union{Int64, Missings.Missing}[4, 7, missing, missing, missing, missing, missing, missing, missing, missing, missing]
Union{Int64, Missing}[5, 6, 7, 9, 16, 2, 3, 4, 7, missing, missing]
Union{Int64, Missing}[2, 3, 4, 7, missing, missing, missing, missing, missing, missing, missing]
Union{Int64, Missing}[4, 7, missing, missing, missing, missing, missing, missing, missing, missing, missing]
```

Then to compute sum of the values of `data` in a range of `-1:2` aligned around `times`, we can simply do:
Expand Down
1 change: 0 additions & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
julia 1.0
Missings
OffsetArrays
RecursiveArrayTools
1 change: 0 additions & 1 deletion src/ShiftedArrays.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
__precompile__()
module ShiftedArrays

using Missings
using RecursiveArrayTools, OffsetArrays

import Base: reduce, mapreduce, checkbounds, getindex, setindex!, parent, size
Expand Down
16 changes: 8 additions & 8 deletions src/lag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ to shift in each dimension. If it is an integer, it is assumed to refer to the f
julia> v = [1, 3, 5, 4];
julia> lag(v)
4-element ShiftedArrays.ShiftedArray{Int64,Missings.Missing,1,Array{Int64,1}}:
4-element ShiftedArrays.ShiftedArray{Int64,Missing,1,Array{Int64,1}}:
missing
1
3
Expand All @@ -21,15 +21,15 @@ julia> w = 1:2:9
1:2:9
julia> s = lag(w, 2)
5-element ShiftedArrays.ShiftedArray{Int64,Missings.Missing,1,StepRange{Int64,Int64}}:
5-element ShiftedArrays.ShiftedArray{Int64,Missing,1,StepRange{Int64,Int64}}:
missing
missing
1
3
5
julia> copy(s)
5-element Array{Union{Int64, Missings.Missing},1}:
5-element Array{Union{Int64, Missing},1}:
missing
missing
1
Expand All @@ -39,7 +39,7 @@ julia> copy(s)
julia> v = reshape(1:16, 4, 4);
julia> s = lag(v, (0, 2))
4×4 ShiftedArrays.ShiftedArray{Int64,Missings.Missing,2,Base.ReshapedArray{Int64,2,UnitRange{Int64},Tuple{}}}:
4×4 ShiftedArrays.ShiftedArray{Int64,Missing,2,Base.ReshapedArray{Int64,2,UnitRange{Int64},Tuple{}}}:
missing missing 1 5
missing missing 2 6
missing missing 3 7
Expand All @@ -61,7 +61,7 @@ to the first dimension. `default` specifies a default value when you are out of
julia> v = [1, 3, 5, 4];
julia> lead(v)
4-element ShiftedArrays.ShiftedArray{Int64,Missings.Missing,1,Array{Int64,1}}:
4-element ShiftedArrays.ShiftedArray{Int64,Missing,1,Array{Int64,1}}:
3
5
4
Expand All @@ -71,15 +71,15 @@ julia> w = 1:2:9
1:2:9
julia> s = lead(w, 2)
5-element ShiftedArrays.ShiftedArray{Int64,Missings.Missing,1,StepRange{Int64,Int64}}:
5-element ShiftedArrays.ShiftedArray{Int64,Missing,1,StepRange{Int64,Int64}}:
5
7
9
missing
missing
julia> copy(s)
5-element Array{Union{Int64, Missings.Missing},1}:
5-element Array{Union{Int64, Missing},1}:
5
7
9
Expand All @@ -89,7 +89,7 @@ julia> copy(s)
julia> v = reshape(1:16, 4, 4);
julia> s = lead(v, (0, 2))
4×4 ShiftedArrays.ShiftedArray{Int64,Missings.Missing,2,Base.ReshapedArray{Int64,2,UnitRange{Int64},Tuple{}}}:
4×4 ShiftedArrays.ShiftedArray{Int64,Missing,2,Base.ReshapedArray{Int64,2,UnitRange{Int64},Tuple{}}}:
9 13 missing missing
10 14 missing missing
11 15 missing missing
Expand Down
24 changes: 12 additions & 12 deletions src/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ function. Indices for which the iterable is empty will return `default`.
julia> v = [1, 3, 5, 9, 6, 7];
julia> ss = ShiftedArray.((v,), [-2, -4])
2-element Array{ShiftedArrays.ShiftedArray{Int64,Missings.Missing,1,Array{Int64,1}},1}:
Union{Int64, Missings.Missing}[5, 9, 6, 7, missing, missing]
Union{Int64, Missings.Missing}[6, 7, missing, missing, missing, missing]
2-element Array{ShiftedArrays.ShiftedArray{Int64,Missing,1,Array{Int64,1}},1}:
Union{Int64, Missing}[5, 9, 6, 7, missing, missing]
Union{Int64, Missing}[6, 7, missing, missing, missing, missing]
julia> reduce(+, ss, 1:2)
2-element Array{Int64,1}:
Expand Down Expand Up @@ -48,9 +48,9 @@ function. Indices for which the iterable is empty will return `default`.
julia> v = [1, 3, 5, 9, 6, 7];
julia> ss = ShiftedArray.((v,), [-2, -4])
2-element Array{ShiftedArrays.ShiftedArray{Int64,Missings.Missing,1,Array{Int64,1}},1}:
Union{Int64, Missings.Missing}[5, 9, 6, 7, missing, missing]
Union{Int64, Missings.Missing}[6, 7, missing, missing, missing, missing]
2-element Array{ShiftedArrays.ShiftedArray{Int64,Missing,1,Array{Int64,1}},1}:
Union{Int64, Missing}[5, 9, 6, 7, missing, missing]
Union{Int64, Missing}[6, 7, missing, missing, missing, missing]
julia> mapreduce(t -> t^2, +, ss, 1:2)
2-element Array{Int64,1}:
Expand Down Expand Up @@ -85,9 +85,9 @@ iterable is empty will return `default`.
julia> v = [1, 3, 5, 9, 6, 7];
julia> ss = ShiftedArray.((v,), [-2, -4])
2-element Array{ShiftedArrays.ShiftedArray{Int64,Missings.Missing,1,Array{Int64,1}},1}:
Union{Int64, Missings.Missing}[5, 9, 6, 7, missing, missing]
Union{Int64, Missings.Missing}[6, 7, missing, missing, missing, missing]
2-element Array{ShiftedArrays.ShiftedArray{Int64,Missing,1,Array{Int64,1}},1}:
Union{Int64, Missing}[5, 9, 6, 7, missing, missing]
Union{Int64, Missing}[6, 7, missing, missing, missing, missing]
julia> reduce_vec(mean, ss, 1:2)
2-element Array{Float64,1}:
Expand Down Expand Up @@ -122,9 +122,9 @@ iterable is empty will return `default`.
julia> v = [1, 3, 5, 9, 6, 7];
julia> ss = ShiftedArray.((v,), [-2, -4])
2-element Array{ShiftedArrays.ShiftedArray{Int64,Missings.Missing,1,Array{Int64,1}},1}:
Union{Int64, Missings.Missing}[5, 9, 6, 7, missing, missing]
Union{Int64, Missings.Missing}[6, 7, missing, missing, missing, missing]
2-element Array{ShiftedArrays.ShiftedArray{Int64,Missing,1,Array{Int64,1}},1}:
Union{Int64, Missing}[5, 9, 6, 7, missing, missing]
Union{Int64, Missing}[6, 7, missing, missing, missing, missing]
julia> mapreduce_vec(log, mean, ss, 1:2)
2-element Array{Float64,1}:
Expand Down
8 changes: 4 additions & 4 deletions src/shiftedarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The recommended constructor is `ShiftedArray(parent, shifts; default = missing)`
julia> v = [1, 3, 5, 4];
julia> s = ShiftedArray(v, (1,))
4-element ShiftedArrays.ShiftedArray{Int64,Missings.Missing,1,Array{Int64,1}}:
4-element ShiftedArrays.ShiftedArray{Int64,Missing,1,Array{Int64,1}}:
missing
1
3
Expand All @@ -27,14 +27,14 @@ julia> s = ShiftedArray(v, (1,))
julia> v = [1, 3, 5, 4];
julia> s = ShiftedArray(v, (1,))
4-element ShiftedArrays.ShiftedArray{Int64,Missings.Missing,1,Array{Int64,1}}:
4-element ShiftedArrays.ShiftedArray{Int64,Missing,1,Array{Int64,1}}:
missing
1
3
5
julia> copy(s)
4-element Array{Union{Int64, Missings.Missing},1}:
4-element Array{Union{Int64, Missing},1}:
missing
1
3
Expand All @@ -43,7 +43,7 @@ julia> copy(s)
julia> v = reshape(1:16, 4, 4);
julia> s = ShiftedArray(v, (0, 2))
4×4 ShiftedArrays.ShiftedArray{Int64,Missings.Missing,2,Base.ReshapedArray{Int64,2,UnitRange{Int64},Tuple{}}}:
4×4 ShiftedArrays.ShiftedArray{Int64,Missing,2,Base.ReshapedArray{Int64,2,UnitRange{Int64},Tuple{}}}:
missing missing 1 5
missing missing 2 6
missing missing 3 7
Expand Down
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ShiftedArrays, Missings, OffsetArrays
using ShiftedArrays, OffsetArrays
using Test

@testset "ShiftedVector" begin
Expand All @@ -14,7 +14,7 @@ using Test
svneg = ShiftedVector(v, -1, default = -100)
@test default(svneg) == -100
@test copy(svneg) == coalesce.(sv, -100)
@test isequal(sv[-3:3], Union{Int64, Missings.Missing}[missing, missing, missing, 1, 3, 5, 4])
@test isequal(sv[-3:3], Union{Int64, Missing}[missing, missing, missing, 1, 3, 5, 4])
end

@testset "ShiftedArray" begin
Expand Down

0 comments on commit e2bfc02

Please sign in to comment.