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

Rewrite select! to improve performance #1985

Merged
merged 6 commits into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 4 additions & 0 deletions src/DataFrames.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ if VERSION < v"1.2"
export hasproperty
end

if VERSION < v"1.1"
import Future.copy!
Ellipse0934 marked this conversation as resolved.
Show resolved Hide resolved
end

##############################################################################
##
## Load files
Expand Down
13 changes: 5 additions & 8 deletions src/dataframe/dataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -818,15 +818,12 @@ function select!(df::DataFrame, inds::AbstractVector{Int})
if !allunique(inds)
throw(ArgumentError("indices must not contain duplicates"))
end

targetnames = _names(df)[inds]
for i in setdiff(ncol(df):-1:1, inds)
splice!(_columns(df), i)
delete!(index(df), i)
copy!(_names(df), _names(df)[inds])
nalimilan marked this conversation as resolved.
Show resolved Hide resolved
copy!(_columns(df), _columns(df)[inds])
nalimilan marked this conversation as resolved.
Show resolved Hide resolved
empty!(index(df).lookup)
for (i, n) in enumerate(_names(df))
index(df).lookup[n] = i
Ellipse0934 marked this conversation as resolved.
Show resolved Hide resolved
end
p = index(df)[targetnames]
permute!(index(df), p)
permute!(_columns(df), p)
df
end

Expand Down
13 changes: 0 additions & 13 deletions src/other/index.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,6 @@ rename!(f::Function, x::Index) = rename!(x, [(x=>f(x)) for x in x.names])
rename(x::Index, args...) = rename!(copy(x), args...)
rename(f::Function, x::Index) = rename!(f, copy(x))

@inline function Base.permute!(x::Index, p::AbstractVector)
@boundscheck if !(length(p) == length(x) && isperm(p))
throw(ArgumentError("$p is not a valid column permutation for this Index"))
end
oldnames = copy(_names(x))
for (i, j) in enumerate(p)
n = oldnames[j]
x.names[i] = n
x.lookup[n] = i
end
x
end

Base.haskey(x::Index, key::Symbol) = haskey(x.lookup, key)
Base.haskey(x::Index, key::Integer) = 1 <= key <= length(x.names)
Base.haskey(x::Index, key::Bool) =
Expand Down