Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BREAKING] Return 0 missing count for columns of nonmissing type #2360

Merged
merged 3 commits into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"julia.environmentPath": "c:\\Users\\ngudat\\.julia\\dev\\DataFrames.jl"
bkamins marked this conversation as resolved.
Show resolved Hide resolved
}
15 changes: 6 additions & 9 deletions src/abstractdataframe/abstractdataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -476,10 +476,7 @@ number of unique values in a column. If a column's base type derives from `Real`
`:nunique` will return `nothing`s.

Missing values are filtered in the calculation of all statistics, however the
column `:nmissing` will report the number of missing values of that variable. If
the column does not allow missing values, `nothing` is returned. Consequently,
`nmissing = 0` indicates that the column allows missing values, but does not
currently contain any.
column `:nmissing` will report the number of missing values of that variable.

If custom functions are provided, they are called repeatedly with the vector
corresponding to each column as the only argument. For columns allowing for
Expand All @@ -494,11 +491,11 @@ julia> df = DataFrame(i=1:10, x=0.1:0.1:1.0, y='a':'j');
julia> describe(df)
3×7 DataFrame
│ Row │ variable │ mean │ min │ median │ max │ nmissing │ eltype │
│ │ Symbol │ Union… │ Any │ Union… │ Any │ Nothing │ DataType │
│ │ Symbol │ Union… │ Any │ Union… │ Any │ Int64 │ DataType │
├─────┼──────────┼────────┼─────┼────────┼─────┼──────────┼──────────┤
│ 1 │ i │ 5.5 │ 1 │ 5.5 │ 10 │ │ Int64 │
│ 2 │ x │ 0.55 │ 0.1 │ 0.55 │ 1.0 │ │ Float64 │
│ 3 │ y │ │ 'a' │ │ 'j' │ │ Char │
│ 1 │ i │ 5.5 │ 1 │ 5.5 │ 10 │ 0 │ Int64 │
│ 2 │ x │ 0.55 │ 0.1 │ 0.55 │ 1.0 │ 0 │ Float64 │
│ 3 │ y │ │ 'a' │ │ 'j' │ 0 │ Char │

julia> describe(df, :min, :max)
3×3 DataFrame
Expand Down Expand Up @@ -580,7 +577,7 @@ function _describe(df::AbstractDataFrame, stats::AbstractVector)
end

if :nmissing in predefined_funs
d[:nmissing] = eltype(col) >: Missing ? count(ismissing, col) : nothing
d[:nmissing] = count(ismissing, col)
end

if :first in predefined_funs
Expand Down
2 changes: 1 addition & 1 deletion test/dataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ end
q75 = [3.25, 2.5, nothing, nothing, nothing, nothing],
max = [4.0, 3.0, "d", "c", Date(2004), 2],
nunique = [nothing, nothing, 4, 3, 4, 2],
nmissing = [nothing, 1, nothing, 1, nothing, nothing],
nmissing = [0, 1, 0, 1, 0, 0],
first = [1, 1, "a", "a", Date(2000), 1],
last = [4, missing, "d", missing, Date(2004), 2],
eltype = [Int, Union{Missing, Int}, String,
Expand Down