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

Improve inference in vcat #2559

Merged
merged 6 commits into from
Nov 25, 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
33 changes: 24 additions & 9 deletions src/abstractdataframe/abstractdataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1547,12 +1547,25 @@ Base.vcat(dfs::AbstractDataFrame...;
AbstractVector{<:AbstractString}}=:setequal) =
reduce(vcat, dfs; cols=cols)

Base.reduce(::typeof(vcat),
dfs::Union{AbstractVector{<:AbstractDataFrame},
Tuple{Vararg{AbstractDataFrame}}};
cols::Union{Symbol, AbstractVector{Symbol},
AbstractVector{<:AbstractString}}=:setequal) =
_vcat([df for df in dfs if ncol(df) != 0]; cols=cols)
if Base.VERSION >= v"1.5"
function Base.reduce(::typeof(vcat),
dfs::Union{AbstractVector{DF},Tuple{Vararg{DF}}};
cols::Union{Symbol, AbstractVector{Symbol},
AbstractVector{<:AbstractString}}=:setequal) where DF<:AbstractDataFrame
if @isdefined(DF) && isconcretetype(DF)
return _vcat(DF[df for df in dfs if ncol(df) != 0]; cols=cols)
else
return _vcat(AbstractDataFrame[df for df in dfs if ncol(df) != 0]; cols=cols)
end
end
else
Base.reduce(::typeof(vcat),
dfs::Union{AbstractVector{<:AbstractDataFrame},
Tuple{Vararg{AbstractDataFrame}}};
cols::Union{Symbol, AbstractVector{Symbol},
AbstractVector{<:AbstractString}}=:setequal) =
_vcat([df for df in dfs if ncol(df) != 0]; cols=cols)
end

function _vcat(dfs::AbstractVector{<:AbstractDataFrame};
cols::Union{Symbol, AbstractVector{Symbol},
Expand Down Expand Up @@ -1586,13 +1599,15 @@ function _vcat(dfs::AbstractVector{<:AbstractDataFrame};

if !isempty(coldiff)
# if any DataFrames are a full superset of names, skip them
filter!(u -> !issetequal(u, header), uniqueheaders)
let header=header # julia #15276
filter!(u -> !issetequal(u, header), uniqueheaders)
end
estrings = map(enumerate(uniqueheaders)) do (i, head)
matching = findall(h -> head == h, allheaders)
headerdiff = setdiff(coldiff, head)
cols = join(headerdiff, ", ", " and ")
badcols = join(headerdiff, ", ", " and ")
args = join(matching, ", ", " and ")
return "column(s) $cols are missing from argument(s) $args"
return "column(s) $badcols are missing from argument(s) $args"
end
throw(ArgumentError(join(estrings, ", ", ", and ")))
end
Expand Down
2 changes: 1 addition & 1 deletion src/other/index.jl
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ Base.@propagate_inbounds SubIndex(parent::AbstractIndex, cols) =
SubIndex(parent, parent[cols])

Base.length(x::SubIndex) = length(x.cols)
Base.names(x::SubIndex) = string.(_names(x))
Base.names(x::SubIndex) = string.(_names(x))::Vector{String}
bkamins marked this conversation as resolved.
Show resolved Hide resolved
_names(x::SubIndex) = view(_names(x.parent), x.cols)

function Base.haskey(x::SubIndex, key::Symbol)
Expand Down