Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
cdef813
Remove `context` to simplify imputation code.
rofinn Sep 29, 2020
f1c863f
Replace context limits with a threshold assertion type.
rofinn Sep 29, 2020
640e2cb
Introduce function interface for threshold.
rofinn Sep 29, 2020
1500ece
Initial work on improving support for `dims` and other cleanup.
rofinn Sep 30, 2020
4772961
Finished reworking dims changes.
rofinn Oct 1, 2020
6e6497e
Simplify dims code a bit more by explicitly using NamedDims.jl
rofinn Oct 1, 2020
43fc0fc
Chain is no longer an imputor.
rofinn Oct 1, 2020
c992d51
Added a Standardize imputor which handles replace user defined 'missi…
rofinn Oct 2, 2020
bc15b8f
Replaced Impute.Fill with Impute.Replace for constants and Impute.Sub…
rofinn Oct 3, 2020
10f3737
Update doctests and run documenter doctests in runtests.jl.
rofinn Oct 6, 2020
8ed73e4
Finish moving various imputor testsets into independent files.
rofinn Oct 6, 2020
850d119
Added more NamedDims and AxisKeys tests.
rofinn Oct 6, 2020
0bba5aa
Lots of documentation updates and minor bug fixes/improvements.
rofinn Oct 8, 2020
af45737
Run CI on julia 1.5 and move deprecated matrix block into jobs so doc…
rofinn Oct 8, 2020
8213ce3
Removed redundant/unreachable code and added more tests.
rofinn Oct 9, 2020
27dfb99
Minor changes from review comments.
rofinn Oct 11, 2020
701d85b
Use a ThresholdError for clearer error messages.
rofinn Oct 11, 2020
bb98aa9
Fix outdated imputor docstring.
rofinn Oct 11, 2020
6c3b6d8
Test Threshold showerror method.
rofinn Oct 14, 2020
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
1 change: 0 additions & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ makedocs(
pages=[
"Home" => "index.md",
"Impute" => "api/impute.md",
"Context" => "api/context.md",
"Imputors" => "api/imputors.md",
"Utilities" => "api/utils.md",
],
Expand Down
5 changes: 0 additions & 5 deletions docs/src/api/context.md

This file was deleted.

47 changes: 23 additions & 24 deletions src/Impute.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@ end

Base.showerror(io::IO, err::ImputeError) = println(io, "ImputeError: $(err.msg)")

include("context.jl")
include("imputors.jl")

#=
These default methods are required because @auto_hash_equals doesn't
play nice with Base.@kwdef
=#
function Base.hash(imp::T, h::UInt) where T <: Union{Imputor, AbstractContext}
function Base.hash(imp::T, h::UInt) where T <: Imputor
h = hash(Symbol(T), h)

for f in fieldnames(T)
Expand All @@ -47,7 +46,7 @@ function Base.hash(imp::T, h::UInt) where T <: Union{Imputor, AbstractContext}
return h
end

function Base.:(==)(a::T, b::T) where T <: Union{Imputor, AbstractContext}
function Base.:(==)(a::T, b::T) where T <: Imputor
result = true

for f in fieldnames(T)
Expand Down Expand Up @@ -89,14 +88,14 @@ for (f, v) in pairs(imputation_methods)
end

@doc """
Impute.dropobs(data; dims=1, context=Context())
Impute.dropobs(data; dims=1)

Removes missing observations from the `AbstractArray` or `Tables.table` provided.
See [DropObs](@ref) for details.

# Example
```
julia> using DataFrames; using Impute: Impute, Context
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
Expand All @@ -109,7 +108,7 @@ julia> df = DataFrame(:a => [1.0, 2.0, missing, missing, 5.0], :b => [1.1, 2.2,
│ 4 │ missing │ missing │
│ 5 │ 5.0 │ 5.5 │

julia> Impute.dropobs(df; dims=2, context=Context(; limit=1.0))
julia> Impute.dropobs(df; dims=2)
3×2 DataFrames.DataFrame
│ Row │ a │ b │
│ │ Float64 │ Float64 │
Expand All @@ -121,14 +120,14 @@ julia> Impute.dropobs(df; dims=2, context=Context(; limit=1.0))
""" dropobs

@doc """
Impute.dropvars(data; dims=1, context=Context())
Impute.dropvars(data; dims=1)

Finds variables with too many missing values in a `AbstractMatrix` or `Tables.table` and
removes them from the input data. See [DropVars](@ref) for details.

# Example
```jldoctest
julia> using DataFrames; using Impute: Impute, Context
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
Expand All @@ -141,7 +140,7 @@ julia> df = DataFrame(:a => [1.0, 2.0, missing, missing, 5.0], :b => [1.1, 2.2,
│ 4 │ missing │ missing │
│ 5 │ 5.0 │ 5.5 │

julia> Impute.dropvars(df; context=Context(; limit=0.2))
julia> Impute.dropvars(df)
5×1 DataFrames.DataFrame
│ Row │ b │
│ │ Float64 │
Expand All @@ -155,14 +154,14 @@ julia> Impute.dropvars(df; context=Context(; limit=0.2))
""" dropvars

@doc """
Impute.interp(data; dims=1, context=Context())
Impute.interp(data; dims=1)

Performs linear interpolation between the nearest values in an vector.
See [Interpolate](@ref) for details.

# Example
```jldoctest
julia> using DataFrames; using Impute: Impute, Context
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
Expand All @@ -175,7 +174,7 @@ julia> df = DataFrame(:a => [1.0, 2.0, missing, missing, 5.0], :b => [1.1, 2.2,
│ 4 │ missing │ missing │
│ 5 │ 5.0 │ 5.5 │

julia> Impute.interp(df; context=Context(; limit=1.0))
julia> Impute.interp(df)
5×2 DataFrames.DataFrame
│ Row │ a │ b │
│ │ Float64 │ Float64 │
Expand All @@ -189,13 +188,13 @@ julia> Impute.interp(df; context=Context(; limit=1.0))
""" interp

@doc """
Impute.fill(data; value=mean, dims=1, context=Context())
Impute.fill(data; value=mean, dims=1)

Fills in the missing data with a specific value. See [Fill](@ref) for details.

# Example
```jldoctest
julia> using DataFrames; using Impute: Impute, Context
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
Expand All @@ -208,7 +207,7 @@ julia> df = DataFrame(:a => [1.0, 2.0, missing, missing, 5.0], :b => [1.1, 2.2,
│ 4 │ missing │ missing │
│ 5 │ 5.0 │ 5.5 │

julia> Impute.fill(df; value=-1.0, context=Context(; limit=1.0))
julia> Impute.fill(df; value=-1.0)
5×2 DataFrames.DataFrame
│ Row │ a │ b │
│ │ Float64 │ Float64 │
Expand All @@ -222,14 +221,14 @@ julia> Impute.fill(df; value=-1.0, context=Context(; limit=1.0))
""" fill

@doc """
Impute.locf(data; dims=1, context=Context())
Impute.locf(data; dims=1)

Iterates forwards through the `data` and fills missing data with the last existing
observation. See [LOCF](@ref) for details.

# Example
```jldoctest
julia> using DataFrames; using Impute: Impute, Context
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
Expand All @@ -242,7 +241,7 @@ julia> df = DataFrame(:a => [1.0, 2.0, missing, missing, 5.0], :b => [1.1, 2.2,
│ 4 │ missing │ missing │
│ 5 │ 5.0 │ 5.5 │

julia> Impute.locf(df; context=Context(; limit=1.0))
julia> Impute.locf(df)
5×2 DataFrames.DataFrame
│ Row │ a │ b │
│ │ Float64 │ Float64 │
Expand All @@ -256,14 +255,14 @@ julia> Impute.locf(df; context=Context(; limit=1.0))
""" locf

@doc """
Impute.nocb(data; dims=1, context=Context())
Impute.nocb(data; dims=1)

Iterates backwards through the `data` and fills missing data with the next existing
observation. See [LOCF](@ref) for details.

# Example
```jldoctest
julia> using DataFrames; using Impute: Impute, Context
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
Expand All @@ -276,7 +275,7 @@ julia> df = DataFrame(:a => [1.0, 2.0, missing, missing, 5.0], :b => [1.1, 2.2,
│ 4 │ missing │ missing │
│ 5 │ 5.0 │ 5.5 │

julia> Impute.nocb(df; context=Context(; limit=1.0))
julia> Impute.nocb(df)
5×2 DataFrames.DataFrame
│ Row │ a │ b │
│ │ Float64 │ Float64 │
Expand All @@ -290,15 +289,15 @@ julia> Impute.nocb(df; context=Context(; limit=1.0))
""" nocb

@doc """
Impute.srs(data; rng=Random.GLOBAL_RNG, context=Context())
Impute.srs(data; rng=Random.GLOBAL_RNG)

Simple Random Sampling (SRS) imputation is a method for imputing both continuous and
categorical variables. Furthermore, it completes imputation while preserving the
distributional properties of the variables (e.g., mean, standard deviation).

# Example
```jldoctest
julia> using DataFrames; using Random; using Impute: Impute, Context
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
Expand All @@ -311,7 +310,7 @@ julia> df = DataFrame(:a => [1.0, 2.0, missing, missing, 5.0], :b => [1.1, 2.2,
│ 4 │ missing │ missing │
│ 5 │ 5.0 │ 5.5 │

julia> Impute.srs(df; rng=MersenneTwister(1234), context=Context(; limit=1.0))
julia> Impute.srs(df; rng=MersenneTwister(1234))
5×2 DataFrame
│ Row │ a │ b │
│ │ Float64 │ Float64 │
Expand Down
Loading