Skip to content

Commit

Permalink
Merge pull request #67 from invenia/rf/cleanup-tests
Browse files Browse the repository at this point in the history
Cleanup of old/noisy tests
  • Loading branch information
rofinn authored Sep 28, 2020
2 parents 76e9d8b + c531e15 commit 2f64a27
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 455 deletions.
30 changes: 0 additions & 30 deletions .appveyor.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Impute"
uuid = "f7bf1975-0170-51b9-8c5f-a992d46b9575"
authors = ["Invenia Technical Computing"]
version = "0.5.1"
version = "0.6.0"

[deps]
Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
Expand Down
28 changes: 0 additions & 28 deletions src/Impute.jl
Original file line number Diff line number Diff line change
Expand Up @@ -324,32 +324,4 @@ julia> Impute.srs(df; rng=MersenneTwister(1234), context=Context(; limit=1.0))
```
""" srs

"""
svd!(data::AbstractMatrix; limit=1.0)
Utility method for `impute!(data, :svd; limit=limit)`
"""
svd!(data::AbstractMatrix; limit=1.0) = impute!(data, :svd; limit=limit)

"""
svd(data::AbstractMatrix; limit=1.0)
Utility method for `impute(data, :svd; limit=limit)`
"""
svd(data::AbstractMatrix; limit=1.0) = impute(data, :svd; limit=limit)

"""
knn!(data::AbstractMatrix; limit=1.0)
Utility method for `impute!(data, :knn; limit=limit)`
"""
knn!(data::AbstractMatrix; limit=1.0) = impute!(data, :knn; limit=limit)

"""
knn(data::AbstractMatrix; limit=1.0)
Utility method for `impute(data, :knn; limit=limit)`
"""
knn(data::AbstractMatrix; limit=1.0) = impute(data, :knn; limit=limit)

end # module
186 changes: 0 additions & 186 deletions src/deprecated.jl
Original file line number Diff line number Diff line change
@@ -1,186 +0,0 @@
###############################################################################
# Deprecations for calling impute on an Imputor with a custom AbstractContext #
###############################################################################
Base.@deprecate(
impute(imp::Imputor, context::AbstractContext, data; kwargs...),
impute(data, typeof(imp)(; context=context, kwargs...))
)

Base.@deprecate(
impute!(imp::Imputor, context::AbstractContext, data; kwargs...),
impute!(data, typeof(imp)(; context=context, kwargs...))
)

Base.@deprecate impute(imp::Imputor, data) impute(data, imp)
Base.@deprecate impute!(imp::Imputor, data) impute!(data, imp)

#####################################################################
# Deprecate all impute calls where the first argument is an Imputor #
#####################################################################
"""
impute!(data, method::Symbol=:interp, args...; limit::Float64=0.1)
Looks up the `Imputor` type for the `method`, creates it and calls
`impute!(data, imputor::Imputor)` with it.
# Arguments
* `data`: the datset containing missing elements we should impute.
* `method::Symbol`: the imputation method to use
(options: [`:drop`, `:fill`, `:interp`, `:locf`, `:nocb`])
* `args::Any...`: any arguments you should pass to the `Imputor` constructor.
* `limit::Float64`: missing data ratio limit/threshold (default: 0.1)
"""
function impute!(data, method::Symbol, args...; limit::Float64=0.1)
Base.depwarn(
"""
impute!(data, method) is deprecated.
Please use Impute.method!(data) or impute!(data, imputor::Imputor).
""",
:impute!
)
imputor_type = imputation_methods[method]
imputor = if length(args) > 0
imputor_type(args...; context=Context(; limit=limit))
else
imputor_type(; context=Context(; limit=limit))
end

return impute!(data, imputor)
end

"""
impute!(data, missing::Function, method::Symbol=:interp, args...; limit::Float64=0.1)
Creates the appropriate `Imputor` type and `Context` (using `missing` function) in order to call
`impute!(data, imputor::Imputor)` with them.
# Arguments
* `data`: the datset containing missing elements we should impute.
* `missing::Function`: the missing data function to use
* `method::Symbol`: the imputation method to use
(options: [`:drop`, `:fill`, `:interp`, `:locf`, `:nocb`])
* `args::Any...`: any arguments you should pass to the `Imputor` constructor.
* `limit::Float64`: missing data ratio limit/threshold (default: 0.1)
"""
function impute!(data, missing::Function, method::Symbol, args...; limit::Float64=0.1)
Base.depwarn(
"""
impute!(data, missing, method) is deprecated. Please use impute!(data, imputor::Imputor).
""",
:impute!
)
imputor_type = imputation_methods[method]
imputor = if length(args) > 0
imputor_type(args...; context=Context(; is_missing=missing, limit=limit))
else
imputor_type(; context=Context(; is_missing=missing, limit=limit))
end

return impute!(data, imputor)
end

"""
impute(data, args...; kwargs...)
Copies the `data` before calling `impute!(new_data, args...; kwargs...)`
"""
function impute(data, args...; kwargs...)
Base.depwarn(
"""
impute(data, args...; kwargs...) is deprecated.
Please use Impute.method(data) or impute(data, imputor::Imputor).
""",
:impute
)
# Call `deepcopy` because we can trust that it's available for all types.
return impute!(deepcopy(data), args...; kwargs...)
end

#################################
# Deprecate the chain functions #
#################################
"""
chain!(data, missing::Function, imputors::Imputor...; kwargs...)
Creates a `Chain` with `imputors` and calls `impute!(imputor, missing, data; kwargs...)`
"""
function chain!(data, missing::Function, imputors::Imputor...; kwargs...)
Base.depwarn(
"""
chain!(data, missing, imputors...) is deprecated.
Please use data = imp1(data) |> imp2 |> imp3
""",
:chain!
)
return chain!(data, imputors...; is_missing=missing, kwargs...)
end

"""
chain!(data, imputors::Imputor...; kwargs...)
Creates a `Chain` with `imputors` and calls `impute!(data, imputor)`
"""
function chain!(data, imputors::Imputor...; kwargs...)
Base.depwarn(
"""
chain!(data, imputors...) is deprecated.
Please use data = imp1(data) |> imp2 |> imp3
""",
:chain!
)
ctx = Context(; kwargs...)

for imputor in imputors
imp = typeof(imputor)(
(isa(x, AbstractContext) ? ctx : x for x in fieldvalues(imputor))...
)
data = impute!(data, imp)
end

return data
end

"""
chain(data, args...; kwargs...)
Copies the `data` before calling `chain!(data, args...; kwargs...)`
"""
function chain(data, args...; kwargs...)
Base.depwarn(
"""
chain(data, args...) is deprecated.
Please use result = imp1(data) |> imp2 |> imp3
""",
:chain
)
# Call `deepcopy` because we can trust that it's available for all types.
return chain!(deepcopy(data), args...; kwargs...)
end

#####################
# Misc Deprecations #
#####################
Base.@deprecate Fill(val; kwargs...) Fill(; value=val, kwargs...)
Base.@deprecate_binding Drop DropObs false

# This function is just used to support legacy behaviour and should be removed in a
# future release when we dropping accepting the limit kwarg to impute functions.
function _extract_context_kwargs(kwargs...)
d = Dict{Symbol, Any}(kwargs...)
limit = 1.0

if haskey(d, :limit)
limit = d[:limit]
@warn(
"Passing `limit` directly to impute functions is deprecated. " *
"Please pass `context=Context(; limit=$limit)` in the future."
)
delete!(d, :limit)
end

if !haskey(d, :context)
d[:context] = Context(; limit=limit)
end

return d
end
4 changes: 2 additions & 2 deletions src/imputors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ end
# Some utility methods for constructing imputors and imputing data in 1 call.
# NOTE: This is only intended for internal use and is not part of the public API.
function _impute(data, t::Type{T}, kwargs...) where T <: Imputor
imp, rem = splitkwargs(t, _extract_context_kwargs(kwargs...)...)
imp, rem = splitkwargs(t, kwargs...)
return impute(data, imp; rem...)
end

function _impute!(data, t::Type{T}, kwargs...) where T <: Imputor
imp, rem = splitkwargs(t, _extract_context_kwargs(kwargs...)...)
imp, rem = splitkwargs(t, kwargs...)
return impute!(data, imp; rem...)
end

Expand Down
Loading

0 comments on commit 2f64a27

Please sign in to comment.