Skip to content

Commit

Permalink
Update doctests and run documenter doctests in runtests.jl.
Browse files Browse the repository at this point in the history
  • Loading branch information
rofinn committed Oct 6, 2020
1 parent bc15b8f commit 10f3737
Show file tree
Hide file tree
Showing 14 changed files with 112 additions and 92 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ after_success:
jobs:
include:
- stage: "Documentation"
julia: 1.0
julia: 1.5
os: linux
script:
- julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
Expand Down
5 changes: 3 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ TableOperations = "ab02a1b2-a7df-11e8-156e-fb1833f50b87"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"

[compat]
AxisKeys = "0.1.5"
AxisKeys = "0.1"
Distances = "0.8, 0.9"
IterTools = "1.2, 1.3"
Missings = "0.4"
Expand All @@ -35,8 +35,9 @@ Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
RDatasets = "ce6b1742-4840-55fa-b093-852dadbb1d8b"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["AxisArrays", "AxisKeys", "Combinatorics", "DataFrames", "Dates", "Distances", "RDatasets", "Test"]
test = ["AxisArrays", "AxisKeys", "Combinatorics", "DataFrames", "Dates", "Distances", "Documenter", "RDatasets", "Test"]
13 changes: 10 additions & 3 deletions src/chain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,17 @@ Compose new chains with the composition operator
# Example
```jldoctest
julia> using Impute: impute, Interpolate, NOCB, LOCF
julia> using Impute: Impute, Interpolate, NOCB, LOCF
julia> imp = Interpolate() ∘ NOCB() ∘ LOCF()
Impute.Chain(Impute.Imputor[Interpolate(2), NOCB(2), LOCF(2)])
julia> M = [missing 2.0 missing missing 5.0; 1.1 2.2 missing 4.4 missing]
2×5 Array{Union{Missing, Float64},2}:
missing 2.0 missing missing 5.0
1.1 2.2 missing 4.4 missing
julia> Impute.run(M, Interpolate() ∘ NOCB() ∘ LOCF(); dims=:rows)
2×5 Array{Union{Missing, Float64},2}:
2.0 2.0 3.0 4.0 5.0
1.1 2.2 3.3 4.4 4.4
```
"""
Base.:()(a::Transform, b::Transform) = Chain(Transform[a, b])
Expand Down
39 changes: 23 additions & 16 deletions src/deprecated.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Introduced in 0.6
# NOTE: Deprecated Imputor docstrings use julia-repl rather than jldoctest since depwarn
# output isn't consistent across installs.
Base.@deprecate_binding(
AbstractContext,
Assertion,
Expand All @@ -22,15 +24,15 @@ be handled independently.
passed the data with missing data removed (e.g, `mean`)
# Example
```jldoctest
```julia-repl
julia> using Impute: Fill, impute
julia> M = [1.0 2.0 missing missing 5.0; 1.1 2.2 3.3 missing 5.5]
2×5 Array{Union{Missing, Float64},2}:
1.0 2.0 missing missing 5.0
1.1 2.2 3.3 missing 5.5
julia> impute(M, Fill(); dims=2)
julia> impute(M, Fill(); dims=:rows)
2×5 Array{Union{Missing, Float64},2}:
1.0 2.0 2.66667 2.66667 5.0
1.1 2.2 3.3 3.025 5.5
Expand Down Expand Up @@ -106,18 +108,22 @@ end
provided.
# Example
```jldoctest
```julia-repl
julia> using Impute: DropObs, impute
julia> M = [1.0 2.0 missing missing 5.0; 1.1 2.2 3.3 missing 5.5]
2×5 Array{Union{Missing, Float64},2}:
1.0 2.0 missing missing 5.0
1.1 2.2 3.3 missing 5.5
julia> impute(M, DropObs(); dims=2)
2×3 Array{Union{Missing, Float64},2}:
1.0 2.0 5.0
1.1 2.2 5.5
julia> M = [1.0 1.1; 2.0 2.2; missing 3.3; missing missing; 5.0 5.5]
5×2 Array{Union{Missing, Float64},2}:
1.0 1.1
2.0 2.2
missing 3.3
missing missing
5.0 5.5
julia> impute(M, DropObs())
3×2 Array{Union{Missing, Float64},2}:
1.0 1.1
2.0 2.2
5.0 5.5
```
"""
struct DropObs <: Imputor
Expand Down Expand Up @@ -170,17 +176,18 @@ end
`Tables.table` and removes them from the input data.
# Examples
```jldoctest
```julia-repl
julia> using Impute: DropVars, impute
julia> M = [1.0 2.0 missing missing 5.0; 1.1 2.2 3.3 missing 5.5]
2×5 Array{Union{Missing, Float64},2}:
1.0 2.0 missing missing 5.0
1.1 2.2 3.3 missing 5.5
julia> impute(M, DropVars(); dims=2)
1×5 Array{Union{Missing, Float64},2}:
1.1 2.2 3.3 missing 5.5
julia> impute(M, DropVars())
2×3 Array{Union{Missing, Float64},2}:
1.0 2.0 5.0
1.1 2.2 5.5
```
"""
struct DropVars <: Imputor
Expand Down
93 changes: 39 additions & 54 deletions src/functional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ filter!(f::Function; kwargs...) = data -> apply!(data, Filter(f); kwargs...)
See [DropObs](@ref) for details.
# Example
```
```julia-repl
julia> using DataFrames; using Impute: Impute
julia> df = DataFrame(:a => [1.0, 2.0, missing, missing, 5.0], :b => [1.1, 2.2, 3.3, missing, 5.5])
Expand Down Expand Up @@ -141,17 +141,17 @@ julia> Impute.dropobs(df; dims=2)
@doc """
Impute.dropvars(data; dims=1)
[Deprecated] Finds variables with too many missing values in a `AbstractMatrix` or `Tables.table` and
[Deprecated] Finds variables with missing values in a `AbstractMatrix` or `Tables.table` and
removes them from the input data. See [DropVars](@ref) for details.
# Example
```jldoctest
```julia-repl
julia> using DataFrames; using Impute: Impute
julia> df = DataFrame(:a => [1.0, 2.0, missing, missing, 5.0], :b => [1.1, 2.2, 3.3, missing, 5.5])
5×2 DataFrames.DataFrame
5×2 DataFrame
│ Row │ a │ b │
│ │ Float64 │ Float64
│ │ Float64? │ Float64?
├─────┼──────────┼──────────┤
│ 1 │ 1.0 │ 1.1 │
│ 2 │ 2.0 │ 2.2 │
Expand All @@ -160,15 +160,7 @@ julia> df = DataFrame(:a => [1.0, 2.0, missing, missing, 5.0], :b => [1.1, 2.2,
│ 5 │ 5.0 │ 5.5 │
julia> Impute.dropvars(df)
5×1 DataFrames.DataFrame
│ Row │ b │
│ │ Float64 │
├─────┼──────────┤
│ 1 │ 1.1 │
│ 2 │ 2.2 │
│ 3 │ 3.3 │
│ 4 │ missing │
│ 5 │ 5.5 │
0×0 DataFrame
```
""" dropvars

Expand All @@ -183,10 +175,11 @@ containing `missing`s.
```jldoctest
julia> using DataFrames; using Impute: Impute
julia> df = DataFrame(:a => [1.0, 2.0, missing, missing, 5.0], :b => [1.1, 2.2, 3.3, missing, 5.5])
5×2 DataFrames.DataFrame
5×2 DataFrame
│ Row │ a │ b │
│ │ Float64 │ Float64
│ │ Float64? │ Float64?
├─────┼──────────┼──────────┤
│ 1 │ 1.0 │ 1.1 │
│ 2 │ 2.0 │ 2.2 │
Expand All @@ -195,24 +188,16 @@ julia> df = DataFrame(:a => [1.0, 2.0, missing, missing, 5.0], :b => [1.1, 2.2,
│ 5 │ 5.0 │ 5.5 │
julia> Impute.filter(df; dims=:cols)
5×1 DataFrames.DataFrame
│ Row │ b │
│ │ Float64 │
├─────┼──────────┤
│ 1 │ 1.1 │
│ 2 │ 2.2 │
│ 3 │ 3.3 │
│ 4 │ missing │
│ 5 │ 5.5 │
0×0 DataFrame
julia> Impute.filter(df; dims=:rows)
3×2 DataFrames.DataFrame
│ Row │ a │ b
│ │ Float64 │ Float64
├─────┼──────────┼──────────┤
│ 1 │ 1.0 │ 1.1
│ 2 │ 2.0 │ 2.2
│ 3 │ 5.0 │ 5.5
3×2 DataFrame
│ Row │ a │ b │
│ │ Float64 │ Float64 │
├─────┼──────────────────┤
│ 1 │ 1.0 │ 1.1 │
│ 2 │ 2.0 │ 2.2 │
│ 3 │ 5.0 │ 5.5 │
```
""" filter

Expand All @@ -227,9 +212,9 @@ See [Interpolate](@ref) for details.
julia> using DataFrames; using Impute: Impute
julia> df = DataFrame(:a => [1.0, 2.0, missing, missing, 5.0], :b => [1.1, 2.2, 3.3, missing, 5.5])
5×2 DataFrames.DataFrame
5×2 DataFrame
│ Row │ a │ b │
│ │ Float64 │ Float64
│ │ Float64? │ Float64?
├─────┼──────────┼──────────┤
│ 1 │ 1.0 │ 1.1 │
│ 2 │ 2.0 │ 2.2 │
Expand All @@ -238,9 +223,9 @@ julia> df = DataFrame(:a => [1.0, 2.0, missing, missing, 5.0], :b => [1.1, 2.2,
│ 5 │ 5.0 │ 5.5 │
julia> Impute.interp(df)
5×2 DataFrames.DataFrame
5×2 DataFrame
│ Row │ a │ b │
│ │ Float64 │ Float64
│ │ Float64? │ Float64?
├─────┼──────────┼──────────┤
│ 1 │ 1.0 │ 1.1 │
│ 2 │ 2.0 │ 2.2 │
Expand All @@ -256,13 +241,13 @@ julia> Impute.interp(df)
Fills in the missing data with a specific value. See [Fill](@ref) for details.
# Example
```jldoctest
```julia-repl
julia> using DataFrames; using Impute: Impute
julia> df = DataFrame(:a => [1.0, 2.0, missing, missing, 5.0], :b => [1.1, 2.2, 3.3, missing, 5.5])
5×2 DataFrames.DataFrame
5×2 DataFrame
│ Row │ a │ b │
│ │ Float64 │ Float64
│ │ Float64? │ Float64?
├─────┼──────────┼──────────┤
│ 1 │ 1.0 │ 1.1 │
│ 2 │ 2.0 │ 2.2 │
Expand All @@ -271,9 +256,9 @@ julia> df = DataFrame(:a => [1.0, 2.0, missing, missing, 5.0], :b => [1.1, 2.2,
│ 5 │ 5.0 │ 5.5 │
julia> Impute.fill(df; value=-1.0)
5×2 DataFrames.DataFrame
5×2 DataFrame
│ Row │ a │ b │
│ │ Float64 │ Float64
│ │ Float64? │ Float64?
├─────┼──────────┼──────────┤
│ 1 │ 1.0 │ 1.1 │
│ 2 │ 2.0 │ 2.2 │
Expand All @@ -294,9 +279,9 @@ observation. See [LOCF](@ref) for details.
julia> using DataFrames; using Impute: Impute
julia> df = DataFrame(:a => [1.0, 2.0, missing, missing, 5.0], :b => [1.1, 2.2, 3.3, missing, 5.5])
5×2 DataFrames.DataFrame
5×2 DataFrame
│ Row │ a │ b │
│ │ Float64 │ Float64
│ │ Float64? │ Float64?
├─────┼──────────┼──────────┤
│ 1 │ 1.0 │ 1.1 │
│ 2 │ 2.0 │ 2.2 │
Expand All @@ -305,9 +290,9 @@ julia> df = DataFrame(:a => [1.0, 2.0, missing, missing, 5.0], :b => [1.1, 2.2,
│ 5 │ 5.0 │ 5.5 │
julia> Impute.locf(df)
5×2 DataFrames.DataFrame
5×2 DataFrame
│ Row │ a │ b │
│ │ Float64 │ Float64
│ │ Float64? │ Float64?
├─────┼──────────┼──────────┤
│ 1 │ 1.0 │ 1.1 │
│ 2 │ 2.0 │ 2.2 │
Expand All @@ -328,9 +313,9 @@ observation. See [LOCF](@ref) for details.
julia> using DataFrames; using Impute: Impute
julia> df = DataFrame(:a => [1.0, 2.0, missing, missing, 5.0], :b => [1.1, 2.2, 3.3, missing, 5.5])
5×2 DataFrames.DataFrame
5×2 DataFrame
│ Row │ a │ b │
│ │ Float64 │ Float64
│ │ Float64? │ Float64?
├─────┼──────────┼──────────┤
│ 1 │ 1.0 │ 1.1 │
│ 2 │ 2.0 │ 2.2 │
Expand All @@ -339,9 +324,9 @@ julia> df = DataFrame(:a => [1.0, 2.0, missing, missing, 5.0], :b => [1.1, 2.2,
│ 5 │ 5.0 │ 5.5 │
julia> Impute.nocb(df)
5×2 DataFrames.DataFrame
5×2 DataFrame
│ Row │ a │ b │
│ │ Float64 │ Float64
│ │ Float64? │ Float64?
├─────┼──────────┼──────────┤
│ 1 │ 1.0 │ 1.1 │
│ 2 │ 2.0 │ 2.2 │
Expand All @@ -359,13 +344,13 @@ categorical variables. Furthermore, it completes imputation while preserving the
distributional properties of the variables (e.g., mean, standard deviation).
# Example
```jldoctest
```julia-repl
julia> using DataFrames; using Random; using Impute: Impute
julia> df = DataFrame(:a => [1.0, 2.0, missing, missing, 5.0], :b => [1.1, 2.2, 3.3, missing, 5.5])
5×2 DataFrames.DataFrame
5×2 DataFrame
│ Row │ a │ b │
│ │ Float64 │ Float64
│ │ Float64? │ Float64?
├─────┼──────────┼──────────┤
│ 1 │ 1.0 │ 1.1 │
│ 2 │ 2.0 │ 2.2 │
Expand All @@ -376,12 +361,12 @@ julia> df = DataFrame(:a => [1.0, 2.0, missing, missing, 5.0], :b => [1.1, 2.2,
julia> Impute.srs(df; rng=MersenneTwister(1234))
5×2 DataFrame
│ Row │ a │ b │
│ │ Float64 │ Float64
│ │ Float64? │ Float64?
├─────┼──────────┼──────────┤
│ 1 │ 1.0 │ 1.1 │
│ 2 │ 2.0 │ 2.2 │
│ 3 │ 1.0 │ 3.3 │
│ 4 │ 5.0 │ 3.3 │
│ 4 │ 2.0 │ 3.3 │
│ 5 │ 5.0 │ 5.5 │
```
""" srs
2 changes: 1 addition & 1 deletion src/imputors/interp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ julia> M = [1.0 2.0 missing missing 5.0; 1.1 2.2 3.3 missing 5.5]
1.0 2.0 missing missing 5.0
1.1 2.2 3.3 missing 5.5
julia> impute(M, Interpolate(); dims=2)
julia> impute(M, Interpolate(); dims=:rows)
2×5 Array{Union{Missing, Float64},2}:
1.0 2.0 3.0 4.0 5.0
1.1 2.2 3.3 4.4 5.5
Expand Down
2 changes: 1 addition & 1 deletion src/imputors/locf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ julia> M = [1.0 2.0 missing missing 5.0; 1.1 2.2 3.3 missing 5.5]
1.0 2.0 missing missing 5.0
1.1 2.2 3.3 missing 5.5
julia> impute(M, LOCF(); dims=2)
julia> impute(M, LOCF(); dims=:rows)
2×5 Array{Union{Missing, Float64},2}:
1.0 2.0 2.0 2.0 5.0
1.1 2.2 3.3 3.3 5.5
Expand Down
2 changes: 1 addition & 1 deletion src/imputors/nocb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ julia> M = [1.0 2.0 missing missing 5.0; 1.1 2.2 3.3 missing 5.5]
1.0 2.0 missing missing 5.0
1.1 2.2 3.3 missing 5.5
julia> impute(M, NOCB(); dims=2)
julia> impute(M, NOCB(); dims=:rows)
2×5 Array{Union{Missing, Float64},2}:
1.0 2.0 5.0 5.0 5.0
1.1 2.2 3.3 5.5 5.5
Expand Down
2 changes: 1 addition & 1 deletion src/imputors/replace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ If the input data is of a different type then the no replacement will be perform
julia> using Impute: Replace, impute
julia> M = [1.0 2.0 missing missing 5.0; 1.1 2.2 3.3 missing 5.5]
2×5 Array{Union{Nothing, Float64},2}:
2×5 Array{Union{Missing, Float64},2}:
1.0 2.0 missing missing 5.0
1.1 2.2 3.3 missing 5.5
Expand Down
Loading

0 comments on commit 10f3737

Please sign in to comment.