Skip to content

Commit

Permalink
Drop warning and special case dropobs! for vectors.
Browse files Browse the repository at this point in the history
  • Loading branch information
rofinn committed Aug 1, 2019
1 parent c7e1d44 commit 39a1de6
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 24 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,7 @@ julia> Impute.interp(df) |> Impute.locf() |> Impute.nocb()
469-247.6-180.7-70.933.7114.8222.5
```

**Warning**: Your approach should depend on the properties of you data (e.g., [MCAR, MAR, MNAR](https://en.wikipedia.org/wiki/Missing_data#Types_of_missing_data)).
**Warning:**

- Your approach should depend on the properties of you data (e.g., [MCAR, MAR, MNAR](https://en.wikipedia.org/wiki/Missing_data#Types_of_missing_data)).
- In-place calls aren't guaranteedto mutate the original data, but it will try avoid copying if possible.
5 changes: 4 additions & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,7 @@ Finally, we can chain multiple simple methods together to give a complete datase
Impute.interp(df) |> Impute.locf() |> Impute.nocb()
```

Warning: Your approach should depend on the properties of you data (e.g., [MCAR, MAR, MNAR](https://en.wikipedia.org/wiki/Missing_data#Types_of_missing_data)).
**Warning:**

- Your approach should depend on the properties of you data (e.g., [MCAR, MAR, MNAR](https://en.wikipedia.org/wiki/Missing_data#Types_of_missing_data)).
- In-place calls aren't guaranteedto mutate the original data, but it will try avoid copying if possible.
24 changes: 8 additions & 16 deletions src/imputors/drop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ julia> impute(M, DropObs(; context=Context(; limit=1.0)); dims=2)
1.0 2.0 5.0
1.1 2.2 5.5
```
WARNING: In-place dropping of observations is not supported.
"""
struct DropObs <: Imputor
context::AbstractContext
Expand All @@ -31,10 +29,13 @@ end
# TODO: Switch to using Base.@kwdef on 1.1
DropObs(; context=Context()) = DropObs(context)

# Special case impute! for vectors because we know filter! will work
function impute!(data::Vector, imp::DropObs)
imp.context(c -> filter!(x -> !ismissing!(c, x), data))
end

function impute(data::AbstractVector, imp::DropObs)
imp.context() do c
return filter(x -> !ismissing!(c, x), data)
end
imp.context(c -> filter(x -> !ismissing!(c, x), data))
end

function impute(data::AbstractMatrix, imp::DropObs; dims=1)
Expand Down Expand Up @@ -86,8 +87,6 @@ julia> impute(M, DropVars(; context=Context(; limit=0.2)); dims=2)
1×5 Array{Union{Missing, Float64},2}:
1.1 2.2 3.3 missing 5.5
```
WARNING: In-place dropping of variables is not supported.
"""
struct DropVars <: Imputor
context::AbstractContext
Expand Down Expand Up @@ -122,12 +121,5 @@ function impute(table, imp::DropVars)
end

# Add impute! methods to override the default behaviour in imputors.jl
function impute!(data::AbstractMatrix, imp::Union{DropObs, DropVars})
@warn "In-place dropping of observations is not supported"
return impute(data, imp)
end

function impute!(data, imp::Union{DropObs, DropVars})
@warn "In-place dropping of observations is not supported"
return impute(data, imp)
end
impute!(data::AbstractMatrix, imp::Union{DropObs, DropVars}) = impute(data, imp)
impute!(data, imp::Union{DropObs, DropVars}) = impute(data, imp)
5 changes: 2 additions & 3 deletions test/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@

# Mutating method
a2 = copy(a)
a2_ = Impute.drop!(a2; limit=0.2)
@test_broken a2 == expected
@test a2_ == expected
Impute.drop!(a2; limit=0.2)
@test a2 == expected
end

@testset "Interpolate" begin
Expand Down
5 changes: 2 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ import Impute:
@test result == Impute.dropobs(a; context=ctx)

a2 = deepcopy(a)
a2_ = Impute.dropobs!(a2; context=ctx)
@test_broken a2 == expected
@test a2_ == expected
Impute.dropobs!(a2; context=ctx)
@test a2 == expected
end

@testset "Matrix" begin
Expand Down

0 comments on commit 39a1de6

Please sign in to comment.