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

do not use collect in describe #2694

Merged
merged 4 commits into from
Apr 11, 2021
Merged
Changes from all 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
12 changes: 7 additions & 5 deletions src/abstractdataframe/abstractdataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ DataAPI.describe(df::AbstractDataFrame,

DataAPI.describe(df::AbstractDataFrame; cols=:) =
_describe(select(df, cols, copycols=false),
[:mean, :min, :median, :max, :nmissing, :eltype])
Any[:mean, :min, :median, :max, :nmissing, :eltype])

function _describe(df::AbstractDataFrame, stats::AbstractVector)
predefined_funs = Symbol[s for s in stats if s isa Symbol]
Expand All @@ -592,7 +592,7 @@ function _describe(df::AbstractDataFrame, stats::AbstractVector)
throw(ArgumentError(":$not_allowed not allowed." * allowed_msg))
end

custom_funs = Pair[s[1] => Symbol(s[2]) for s in stats if s isa Pair]
custom_funs = Any[s[1] => Symbol(s[2]) for s in stats if s isa Pair]

ordered_names = [s isa Symbol ? s : Symbol(last(s)) for s in stats]

Expand All @@ -610,7 +610,7 @@ function _describe(df::AbstractDataFrame, stats::AbstractVector)
# An array of Dicts for summary statistics
col_stats_dicts = map(eachcol(df)) do col
if eltype(col) >: Missing
t = collect(skipmissing(col))
t = skipmissing(col)
d = get_stats(t, predefined_funs)
get_stats!(d, t, custom_funs)
else
Expand Down Expand Up @@ -649,7 +649,8 @@ end
# Compute summary statistics
# use a dict because we dont know which measures the user wants
# Outside of the `describe` function due to something with 0.7
function get_stats(col::AbstractVector, stats::AbstractVector{Symbol})
function get_stats(@nospecialize(col::Union{AbstractVector, Base.SkipMissing}),
stats::AbstractVector{Symbol})
d = Dict{Symbol, Any}()

if :q25 in stats || :median in stats || :q75 in stats
Expand Down Expand Up @@ -687,7 +688,8 @@ function get_stats(col::AbstractVector, stats::AbstractVector{Symbol})
return d
end

function get_stats!(d::Dict, col::AbstractVector, stats::AbstractVector{<:Pair})
function get_stats!(d::Dict, @nospecialize(col::Union{AbstractVector, Base.SkipMissing}),
stats::Vector{Any})
for stat in stats
d[stat[2]] = try stat[1](col) catch end
end
Expand Down