Skip to content

Commit

Permalink
Improve inference in vcat (#2559)
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy authored Nov 25, 2020
1 parent 8645651 commit 86a5ee6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
25 changes: 14 additions & 11 deletions src/abstractdataframe/abstractdataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@ end

_filter_helper(f, cols...)::BitVector = ((x...) -> f(x...)::Bool).(cols...)

@inline function Base.filter((cols, f)::Pair{<:AsTable}, df::AbstractDataFrame;
@inline function Base.filter((cols, f)::Pair{AsTable}, df::AbstractDataFrame;
view::Bool=false)
df_tmp = select(df, cols.cols, copycols=false)
if ncol(df_tmp) == 0
Expand Down Expand Up @@ -1547,14 +1547,15 @@ 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)
function Base.reduce(::typeof(vcat),
dfs::Union{AbstractVector{<:AbstractDataFrame},
Tuple{AbstractDataFrame, Vararg{AbstractDataFrame}}};
cols::Union{Symbol, AbstractVector{Symbol},
AbstractVector{<:AbstractString}}=:setequal)
return _vcat(AbstractDataFrame[df for df in dfs if ncol(df) != 0]; cols=cols)
end

function _vcat(dfs::AbstractVector{<:AbstractDataFrame};
function _vcat(dfs::AbstractVector{AbstractDataFrame};
cols::Union{Symbol, AbstractVector{Symbol},
AbstractVector{<:AbstractString}}=:setequal)

Expand Down Expand Up @@ -1586,13 +1587,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/groupeddataframe/splitapplycombine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ function prepare_idx_keeprows(idx::AbstractVector{<:Integer},
end

function _combine(gd::GroupedDataFrame,
@nospecialize(cs_norm::Vector{Any}), optional_transform::Vector{Bool},
cs_norm::Vector{Any}, optional_transform::Vector{Bool},
copycols::Bool, keeprows::Bool, renamecols::Bool)
if isempty(cs_norm)
if keeprows && nrow(parent(gd)) > 0 && minimum(gd.groups) == 0
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}
_names(x::SubIndex) = view(_names(x.parent), x.cols)

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

0 comments on commit 86a5ee6

Please sign in to comment.