Skip to content

Commit ac55a99

Browse files
timholynalimilan
authored andcommitted
Improve inference in vcat (#2559)
1 parent 3e225ad commit ac55a99

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

src/abstractdataframe/abstractdataframe.jl

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ end
10231023

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

1026-
@inline function Base.filter((cols, f)::Pair{<:AsTable}, df::AbstractDataFrame;
1026+
@inline function Base.filter((cols, f)::Pair{AsTable}, df::AbstractDataFrame;
10271027
view::Bool=false)
10281028
df_tmp = select(df, cols.cols, copycols=false)
10291029
if ncol(df_tmp) == 0
@@ -1547,14 +1547,15 @@ Base.vcat(dfs::AbstractDataFrame...;
15471547
AbstractVector{<:AbstractString}}=:setequal) =
15481548
reduce(vcat, dfs; cols=cols)
15491549

1550-
Base.reduce(::typeof(vcat),
1551-
dfs::Union{AbstractVector{<:AbstractDataFrame},
1552-
Tuple{Vararg{AbstractDataFrame}}};
1553-
cols::Union{Symbol, AbstractVector{Symbol},
1554-
AbstractVector{<:AbstractString}}=:setequal) =
1555-
_vcat([df for df in dfs if ncol(df) != 0]; cols=cols)
1550+
function Base.reduce(::typeof(vcat),
1551+
dfs::Union{AbstractVector{<:AbstractDataFrame},
1552+
Tuple{AbstractDataFrame, Vararg{AbstractDataFrame}}};
1553+
cols::Union{Symbol, AbstractVector{Symbol},
1554+
AbstractVector{<:AbstractString}}=:setequal)
1555+
return _vcat(AbstractDataFrame[df for df in dfs if ncol(df) != 0]; cols=cols)
1556+
end
15561557

1557-
function _vcat(dfs::AbstractVector{<:AbstractDataFrame};
1558+
function _vcat(dfs::AbstractVector{AbstractDataFrame};
15581559
cols::Union{Symbol, AbstractVector{Symbol},
15591560
AbstractVector{<:AbstractString}}=:setequal)
15601561

@@ -1586,13 +1587,15 @@ function _vcat(dfs::AbstractVector{<:AbstractDataFrame};
15861587

15871588
if !isempty(coldiff)
15881589
# if any DataFrames are a full superset of names, skip them
1589-
filter!(u -> !issetequal(u, header), uniqueheaders)
1590+
let header=header # julia #15276
1591+
filter!(u -> !issetequal(u, header), uniqueheaders)
1592+
end
15901593
estrings = map(enumerate(uniqueheaders)) do (i, head)
15911594
matching = findall(h -> head == h, allheaders)
15921595
headerdiff = setdiff(coldiff, head)
1593-
cols = join(headerdiff, ", ", " and ")
1596+
badcols = join(headerdiff, ", ", " and ")
15941597
args = join(matching, ", ", " and ")
1595-
return "column(s) $cols are missing from argument(s) $args"
1598+
return "column(s) $badcols are missing from argument(s) $args"
15961599
end
15971600
throw(ArgumentError(join(estrings, ", ", ", and ")))
15981601
end

src/groupeddataframe/splitapplycombine.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ function prepare_idx_keeprows(idx::AbstractVector{<:Integer},
489489
end
490490

491491
function _combine(gd::GroupedDataFrame,
492-
@nospecialize(cs_norm::Vector{Any}), optional_transform::Vector{Bool},
492+
cs_norm::Vector{Any}, optional_transform::Vector{Bool},
493493
copycols::Bool, keeprows::Bool, renamecols::Bool, nthreads::Int)
494494
if isempty(cs_norm)
495495
if keeprows && nrow(parent(gd)) > 0 && minimum(gd.groups) == 0

src/other/index.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ Base.@propagate_inbounds SubIndex(parent::AbstractIndex, cols) =
422422
SubIndex(parent, parent[cols])
423423

424424
Base.length(x::SubIndex) = length(x.cols)
425-
Base.names(x::SubIndex) = string.(_names(x))
425+
Base.names(x::SubIndex) = string.(_names(x))::Vector{String}
426426
_names(x::SubIndex) = view(_names(x.parent), x.cols)
427427

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

0 commit comments

Comments
 (0)