Skip to content

Commit

Permalink
Merge 3a45426 into 11a9949
Browse files Browse the repository at this point in the history
  • Loading branch information
bkamins committed Oct 1, 2020
2 parents 11a9949 + 3a45426 commit 6b3600b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 43 deletions.
44 changes: 1 addition & 43 deletions src/dataframe/dataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,11 @@ function DataFrame(pairs::Pair{<:AbstractString,<:Any}...; makeunique::Bool=fals
copycols=copycols)
end

# these two are needed as a workaround Tables.jl dispatch
# this is needed as a workaround for Tables.jl dispatch
DataFrame(pairs::AbstractVector{<:Pair}; makeunique::Bool=false,
copycols::Bool=true) =
DataFrame(pairs..., makeunique=makeunique, copycols=copycols)

DataFrame(pairs::NTuple{N, Pair}; makeunique::Bool=false,
copycols::Bool=true) where {N} =
DataFrame(pairs..., makeunique=makeunique, copycols=copycols)

function DataFrame(d::AbstractDict; copycols::Bool=true)
if isa(d, Dict)
colnames = sort!(collect(keys(d)))
Expand Down Expand Up @@ -249,44 +245,6 @@ DataFrame(columns::AbstractVector{<:AbstractVector},
makeunique::Bool=false, copycols::Bool=true) =
DataFrame(columns, Symbol.(cnames); makeunique=makeunique, copycols=copycols)

DataFrame(columns::NTuple{N, AbstractVector}, cnames::NTuple{N, Symbol};
makeunique::Bool=false, copycols::Bool=true) where {N} =
DataFrame(collect(AbstractVector, columns), collect(Symbol, cnames),
makeunique=makeunique, copycols=copycols)

DataFrame(columns::NTuple{N, AbstractVector}, cnames::NTuple{N, AbstractString};
makeunique::Bool=false, copycols::Bool=true) where {N} =
DataFrame(columns, Symbol.(cnames); makeunique=makeunique, copycols=copycols)

DataFrame(columns::NTuple{N, AbstractVector}; copycols::Bool=true) where {N} =
DataFrame(collect(AbstractVector, columns), gennames(length(columns)),
copycols=copycols)

DataFrame(columns::AbstractMatrix,
cnames::AbstractVector{Symbol} = gennames(size(columns, 2));
makeunique::Bool=false) =
DataFrame(AbstractVector[columns[:, i] for i in 1:size(columns, 2)], cnames,
makeunique=makeunique, copycols=false)

DataFrame(columns::AbstractMatrix, cnames::AbstractVector{<:AbstractString};
makeunique::Bool=false) =
DataFrame(columns, Symbol.(cnames); makeunique=makeunique)

function DataFrame(column_eltypes::AbstractVector{T}, cnames::AbstractVector{Symbol},
nrows::Integer=0; makeunique::Bool=false)::DataFrame where T<:Type
columns = AbstractVector[elty >: Missing ?
fill!(Tables.allocatecolumn(elty, nrows), missing) :
Tables.allocatecolumn(elty, nrows)
for elty in column_eltypes]
return DataFrame(columns, Index(convert(Vector{Symbol}, cnames),
makeunique=makeunique), copycols=false)
end

DataFrame(column_eltypes::AbstractVector{<:Type},
cnames::AbstractVector{<:AbstractString},
nrows::Integer=0; makeunique::Bool=false) =
DataFrame(column_eltypes, Symbol.(cnames), nrows; makeunique=makeunique)

##############################################################################
##
## AbstractDataFrame interface
Expand Down
37 changes: 37 additions & 0 deletions src/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,40 @@ function categorical!(df::DataFrame, cols::Union{Type, Nothing}=nothing;
end
return transform!(df, names(df, cols) .=> (x -> categorical(x, compress=compress)), renamecols=false)
end

@deprecate DataFrame(pairs::NTuple{N, Pair}; makeunique::Bool=false,
copycols::Bool=true) where {N} DataFrame(pairs..., makeunique=makeunique, copycols=copycols)
@deprecate DataFrame(columns::NTuple{N, AbstractVector}, cnames::NTuple{N, Symbol}; makeunique::Bool=false,
copycols::Bool=true) where {N} DataFrame(collect(columns), collect(cnames);
makeunique=makeunique, copycols=copycols)
@deprecate DataFrame(columns::NTuple{N, AbstractVector}, cnames::NTuple{N, AbstractString}; makeunique::Bool=false,
copycols::Bool=true) where {N} DataFrame(collect(columns), [Symbol(c) for c in cnames];
makeunique=makeunique, copycols=copycols)
@deprecate DataFrame(columns::NTuple{N, AbstractVector};
copycols::Bool=true) where {N} DataFrame(collect(columns),
Symbol.(:x, 1:length(columns)), copycols=copycols)
@deprecate DataFrame(columns::AbstractMatrix, cnames::AbstractVector{Symbol} = gennames(size(columns, 2));
makeunique::Bool=false) DataFrame([columns[:, i] for i in 1:size(columns, 2)],
cnames; makeunique=makeunique, copycols=false)

@deprecate DataFrame(columns::AbstractMatrix, cnames::AbstractVector{<:AbstractString};
makeunique::Bool=false) DataFrame([columns[:, i] for i in 1:size(columns, 2)],
Symbol.(cnames); makeunique=makeunique, copycols=false)

function DataFrame(column_eltypes::AbstractVector{T}, cnames::AbstractVector{Symbol},
nrows::Integer=0; makeunique::Bool=false)::DataFrame where T<:Type
Base.depwarn("`DataFrame` constructor with passed eltypes is deprecated. " *
"Pass explicitly created columns to a `DataFrame` constructor instead.",
:DataFrame)
columns = AbstractVector[elty >: Missing ?
fill!(Tables.allocatecolumn(elty, nrows), missing) :
Tables.allocatecolumn(elty, nrows)
for elty in column_eltypes]
return DataFrame(columns, Index(convert(Vector{Symbol}, cnames),
makeunique=makeunique), copycols=false)
end

DataFrame(column_eltypes::AbstractVector{<:Type},
cnames::AbstractVector{<:AbstractString},
nrows::Integer=0; makeunique::Bool=false) =
DataFrame(column_eltypes, Symbol.(cnames), nrows; makeunique=makeunique)

0 comments on commit 6b3600b

Please sign in to comment.