Skip to content

Commit

Permalink
Use skipmissing() instead of Missings.skip()
Browse files Browse the repository at this point in the history
The latter is deprecated.
  • Loading branch information
nalimilan committed Nov 23, 2017
1 parent ff2729b commit 0e65d03
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
julia 0.6
Missings
Missings 0.2.1
CategoricalArrays 0.3.0
StatsBase 0.11.0
SortingAlgorithms
Expand Down
14 changes: 7 additions & 7 deletions docs/src/man/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,21 @@ true
```

`missing` values can be excluded when performing operations by using `Missings.skip`, which returns a memory-efficient iterator.
`missing` values can be excluded when performing operations by using `skipmissing`, which returns a memory-efficient iterator.

```jldoctest missings
julia> Missings.skip(x)
Base.Generator{Base.Iterators.Filter{Missings.##4#6,Array{Union{Int64, Missings.Missing},1}},Missings.##3#5}(Missings.#3, Base.Iterators.Filter{Missings.##4#6,Array{Union{Int64, Missings.Missing},1}}(Missings.#4, Union{Int64, Missings.Missing}[1, 2, missing]))
julia> skipmissing(x)
Missings.EachSkipMissing{Array{Union{$Int, Missings.Missing},1}}(Union{$Int, Missings.Missing}[1, 2, missing])
```

The output of `Missings.skip` can be passed directly into functions as an argument. For example, we can find the `sum` of all non-missing values or `collect` the non-missing values into a new missing-free vector.
The output of `skipmissing` can be passed directly into functions as an argument. For example, we can find the `sum` of all non-missing values or `collect` the non-missing values into a new missing-free vector.

```jldoctest missings
julia> sum(Missings.skip(x))
julia> sum(skipmissing(x))
3
julia> collect(Missings.skip(x))
julia> collect(skipmissing(x))
2-element Array{Int64,1}:
1
2
Expand Down Expand Up @@ -271,7 +271,7 @@ julia> df
│ 7 │ missing │ M │
│ 8 │ 8 │ F │
julia> mean(Missings.skip(df[:A]))
julia> mean(skipmissing(df[:A]))
5.0
```
Expand Down
2 changes: 1 addition & 1 deletion src/abstractdataframe/abstractdataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ function StatsBase.describe(io::IO, X::AbstractVector{Union{T, Missing}}) where
missingcount = count(ismissing, X)
pmissing = 100 * missingcount/length(X)
if pmissing != 100 && T <: Real
show(io, StatsBase.summarystats(collect(Missings.skip(X))))
show(io, StatsBase.summarystats(collect(skipmissing(X))))
else
println(io, "Summary Stats:")
end
Expand Down
20 changes: 10 additions & 10 deletions src/groupeddataframe/grouping.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ vcat([g[:b] for g in gd]...)
for g in gd
println(g)
end
map(d -> mean(Missings.skip(d[:c])), gd) # returns a GroupApplied object
combine(map(d -> mean(Missings.skip(d[:c])), gd))
map(d -> mean(skipmissing(d[:c])), gd) # returns a GroupApplied object
combine(map(d -> mean(skipmissing(d[:c])), gd))
df |> groupby(:a) |> [sum, length]
df |> groupby([:a, :b]) |> [sum, length]
```
Expand Down Expand Up @@ -194,7 +194,7 @@ combine(ga::GroupApplied)
df = DataFrame(a = repeat([1, 2, 3, 4], outer=[2]),
b = repeat([2, 1], outer=[4]),
c = randn(8))
combine(map(d -> mean(Missings.skip(d[:c])), gd))
combine(map(d -> mean(skipmissing(d[:c])), gd))
```
"""
Expand Down Expand Up @@ -291,11 +291,11 @@ df = DataFrame(a = repeat([1, 2, 3, 4], outer=[2]),
b = repeat([2, 1], outer=[4]),
c = randn(8))
by(df, :a, d -> sum(d[:c]))
by(df, :a, d -> 2 * Missings.skip(d[:c]))
by(df, :a, d -> DataFrame(c_sum = sum(d[:c]), c_mean = mean(Missings.skip(d[:c]))))
by(df, :a, d -> DataFrame(c = d[:c], c_mean = mean(Missings.skip(d[:c]))))
by(df, :a, d -> 2 * skipmissing(d[:c]))
by(df, :a, d -> DataFrame(c_sum = sum(d[:c]), c_mean = mean(skipmissing(d[:c]))))
by(df, :a, d -> DataFrame(c = d[:c], c_mean = mean(skipmissing(d[:c]))))
by(df, [:a, :b]) do d
DataFrame(m = mean(Missings.skip(d[:c])), v = var(Missings.skip(d[:c])))
DataFrame(m = mean(skipmissing(d[:c])), v = var(skipmissing(d[:c])))
end
```
Expand Down Expand Up @@ -341,9 +341,9 @@ df = DataFrame(a = repeat([1, 2, 3, 4], outer=[2]),
b = repeat([2, 1], outer=[4]),
c = randn(8))
aggregate(df, :a, sum)
aggregate(df, :a, [sum, x->mean(Missings.skip(x))])
aggregate(groupby(df, :a), [sum, x->mean(Missings.skip(x))])
df |> groupby(:a) |> [sum, x->mean(Missings.skip(x))] # equivalent
aggregate(df, :a, [sum, x->mean(skipmissing(x))])
aggregate(groupby(df, :a), [sum, x->mean(skipmissing(x))])
df |> groupby(:a) |> [sum, x->mean(skipmissing(x))] # equivalent
```
"""
Expand Down
2 changes: 1 addition & 1 deletion src/other/index.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Base.getindex(x::AbstractIndex, idx::AbstractVector{Union{Bool, Missing}}) =
getindex(x, collect(Missings.replace(idx, false)))
Base.getindex(x::AbstractIndex, idx::AbstractVector{Bool}) = find(idx)
Base.getindex(x::AbstractIndex, idx::AbstractVector{T}) where {T >: Missing} =
getindex(x, collect(Missings.skip(idx)))
getindex(x, collect(skipmissing(idx)))
Base.getindex(x::AbstractIndex, idx::Range) = [idx;]
Base.getindex(x::AbstractIndex, idx::AbstractVector{T}) where {T <: Real} = convert(Vector{Int}, idx)
Base.getindex(x::AbstractIndex, idx::AbstractVector{Symbol}) = [x.lookup[i] for i in idx]
Expand Down

0 comments on commit 0e65d03

Please sign in to comment.