diff --git a/src/abstractdataframe/abstractdataframe.jl b/src/abstractdataframe/abstractdataframe.jl index 8f693f0ef3..12caf6db67 100644 --- a/src/abstractdataframe/abstractdataframe.jl +++ b/src/abstractdataframe/abstractdataframe.jl @@ -202,7 +202,7 @@ eltypes(df) ``` """ -eltypes(df::AbstractDataFrame) = eltype.(columns(df)) +eltypes(df::AbstractDataFrame) = eltype.(eachcol(df)) Base.size(df::AbstractDataFrame) = (nrow(df), ncol(df)) function Base.size(df::AbstractDataFrame, i::Integer) @@ -241,7 +241,7 @@ that is different than the number of rows present in `df`. """ function Base.similar(df::AbstractDataFrame, rows::Integer = size(df, 1)) rows < 0 && throw(ArgumentError("the number of rows must be positive")) - DataFrame(Any[similar(x, rows) for x in columns(df)], copy(index(df))) + DataFrame(Any[similar(x, rows) for x in eachcol(df)], copy(index(df))) end ############################################################################## @@ -432,7 +432,7 @@ function StatsBase.describe(df::AbstractDataFrame; stats::Union{Symbol,AbstractV data[:variable] = names(df) # An array of Dicts for summary statistics - column_stats_dicts = [get_stats(col) for col in columns(df)] + column_stats_dicts = [get_stats(col) for col in eachcol(df)] for stat in stats # for each statistic, loop through the columns array to find values # letting the comprehension choose the appropriate type @@ -794,7 +794,7 @@ function Base.convert(::Type{Matrix{T}}, df::AbstractDataFrame) where T n, p = size(df) res = Matrix{T}(undef, n, p) idx = 1 - for (name, col) in zip(names(df), columns(df)) + for (name, col) in eachcol(df, true) try copyto!(res, idx, col) catch err diff --git a/src/abstractdataframe/iteration.jl b/src/abstractdataframe/iteration.jl index 7a257473cf..d27f498804 100644 --- a/src/abstractdataframe/iteration.jl +++ b/src/abstractdataframe/iteration.jl @@ -49,13 +49,12 @@ struct DataFrameColumns{T<:AbstractDataFrame, V} <: AbstractVector{V} end """ - eachcol(df::AbstractDataFrame, names::Bool=true) + eachcol(df::AbstractDataFrame, names::Bool=false) Return a `DataFrameColumns` that iterates an `AbstractDataFrame` column by column. -If `names` is equal to `true` (currently the default, in the future the default -will be set to `false`) iteration returns a pair consisting of column name +If `names` is equal to `true` iteration returns a pair consisting of column name and column vector. -If `names` is equal to `false` then column vectors are yielded. +If `names` is equal to `false` (the default) then column vectors are yielded. **Examples** @@ -70,17 +69,17 @@ julia> df = DataFrame(x=1:4, y=11:14) │ 3 │ 3 │ 13 │ │ 4 │ 4 │ 14 │ +julia> collect(eachcol(df)) +2-element Array{AbstractArray{T,1} where T,1}: + [1, 2, 3, 4] + [11, 12, 13, 14] + julia> collect(eachcol(df, true)) 2-element Array{Pair{Symbol,AbstractArray{T,1} where T},1}: :x => [1, 2, 3, 4] :y => [11, 12, 13, 14] -julia> collect(eachcol(df, false)) -2-element Array{AbstractArray{T,1} where T,1}: - [1, 2, 3, 4] - [11, 12, 13, 14] - -julia> sum.(eachcol(df, false)) +julia> sum.(eachcol(df)) 2-element Array{Int64,1}: 10 50 @@ -93,7 +92,7 @@ julia> map(eachcol(df, false)) do col 3 ``` """ -@inline function eachcol(df::T, names::Bool) where T<: AbstractDataFrame +@inline function eachcol(df::T, names::Bool=false) where T<: AbstractDataFrame if names DataFrameColumns{T, Pair{Symbol, AbstractVector}}(df) else @@ -101,17 +100,6 @@ julia> map(eachcol(df, false)) do col end end -# TODO: remove this method after deprecation -# and add default argument value above -function eachcol(df::AbstractDataFrame) - Base.depwarn("In the future eachcol will have names argument set to false by default", :eachcol) - eachcol(df, true) -end - -# TODO: remove this method after deprecation -# this is left to make sure we do not forget to properly fix columns calls -columns(df::AbstractDataFrame) = eachcol(df, false) - Base.size(itr::DataFrameColumns) = (size(itr.df, 2),) Base.IndexStyle(::Type{<:DataFrameColumns}) = Base.IndexLinear() @@ -178,7 +166,7 @@ julia> mapcols(x -> x.^2, df) function mapcols(f::Union{Function,Type}, df::AbstractDataFrame) # note: `f` must return a consistent length res = DataFrame() - for (n, v) in eachcol(df) + for (n, v) in eachcol(df, true) res[n] = f(v) end res diff --git a/src/abstractdataframe/join.jl b/src/abstractdataframe/join.jl index ef46c45560..2509d4f7b6 100644 --- a/src/abstractdataframe/join.jl +++ b/src/abstractdataframe/join.jl @@ -89,13 +89,13 @@ function compose_joined_table(joiner::DataFrameJoiner, kind::Symbol, cols = Vector{AbstractVector}(undef, ncleft + ncol(dfr_noon)) # inner and left joins preserve non-missingness of the left frame _similar_left = kind == :inner || kind == :left ? similar : similar_missing - for (i, col) in enumerate(columns(joiner.dfl)) + for (i, col) in enumerate(eachcol(joiner.dfl)) cols[i] = _similar_left(col, nrow) copyto!(cols[i], view(col, all_orig_left_ixs)) end # inner and right joins preserve non-missingness of the right frame _similar_right = kind == :inner || kind == :right ? similar : similar_missing - for (i, col) in enumerate(columns(dfr_noon)) + for (i, col) in enumerate(eachcol(dfr_noon)) cols[i+ncleft] = _similar_right(col, nrow) copyto!(cols[i+ncleft], view(col, all_orig_right_ixs)) permute!(cols[i+ncleft], right_perm) @@ -407,7 +407,7 @@ end function crossjoin(df1::AbstractDataFrame, df2::AbstractDataFrame; makeunique::Bool=false) r1, r2 = size(df1, 1), size(df2, 1) colindex = merge(index(df1), index(df2), makeunique=makeunique) - cols = Any[[repeat(c, inner=r2) for c in columns(df1)]; - [repeat(c, outer=r1) for c in columns(df2)]] + cols = Any[[repeat(c, inner=r2) for c in eachcol(df1)]; + [repeat(c, outer=r1) for c in eachcol(df2)]] DataFrame(cols, colindex) end diff --git a/src/dataframerow/dataframerow.jl b/src/dataframerow/dataframerow.jl index ad44abed58..c257b216e3 100644 --- a/src/dataframerow/dataframerow.jl +++ b/src/dataframerow/dataframerow.jl @@ -148,7 +148,7 @@ function isequal_row(df1::AbstractDataFrame, r1::Int, df2::AbstractDataFrame, r2 elseif !(ncol(df1) == ncol(df2)) throw(ArgumentError("Rows of the tables that have different number of columns cannot be compared. Got $(ncol(df1)) and $(ncol(df2)) columns")) end - @inbounds for (col1, col2) in zip(columns(df1), columns(df2)) + @inbounds for (col1, col2) in zip(eachcol(df1), eachcol(df2)) isequal(col1[r1], col2[r2]) || return false end return true diff --git a/src/deprecated.jl b/src/deprecated.jl index e275462497..7e96ec3009 100644 --- a/src/deprecated.jl +++ b/src/deprecated.jl @@ -10,7 +10,7 @@ import Base: @deprecate import Base: keys, values, insert! @deprecate keys(df::AbstractDataFrame) names(df) -@deprecate values(df::AbstractDataFrame) columns(df) +@deprecate values(df::AbstractDataFrame) eachcol(df) @deprecate insert!(df::DataFrame, df2::AbstractDataFrame) (foreach(col -> df[col] = df2[col], names(df2)); df) @deprecate pool categorical @@ -1741,7 +1741,7 @@ end function hashrows(df::SubDataFrame, skipmissing::Bool) rhashes = zeros(UInt, nrow(df)) missings = fill(false, skipmissing ? nrow(df) : 0) - cols = columns(df) + cols = eachcol(df) for i in 1:ncol(df) hashrows_col!(rhashes, missings, view(parent(df)[i], rows(df)), i == 1) end diff --git a/src/groupeddataframe/grouping.jl b/src/groupeddataframe/grouping.jl index 8a4295b400..676c520e67 100644 --- a/src/groupeddataframe/grouping.jl +++ b/src/groupeddataframe/grouping.jl @@ -424,7 +424,7 @@ function _combine(f::Any, gd::GroupedDataFrame) fun = last(f) elseif f isa Pair df = gd.parent[collect(first(f))] - incols = NamedTuple{Tuple(names(df))}(columns(df)) + incols = NamedTuple{Tuple(names(df))}(eachcol(df)) fun = last(f) else incols = nothing diff --git a/test/cat.jl b/test/cat.jl index f3724b7a87..74a5773757 100644 --- a/test/cat.jl +++ b/test/cat.jl @@ -1,6 +1,5 @@ module TestCat using Test, Random, DataFrames - using DataFrames: columns const ≅ = isequal # @@ -165,13 +164,13 @@ module TestCat @testset "vcat mixed coltypes" begin df = vcat(DataFrame([[1]], [:x]), DataFrame([[1.0]], [:x])) @test df == DataFrame([[1.0, 1.0]], [:x]) - @test typeof.(columns(df)) == [Vector{Float64}] + @test typeof.(eachcol(df)) == [Vector{Float64}] df = vcat(DataFrame([[1]], [:x]), DataFrame([["1"]], [:x])) @test df == DataFrame([[1, "1"]], [:x]) - @test typeof.(columns(df)) == [Vector{Any}] + @test typeof.(eachcol(df)) == [Vector{Any}] df = vcat(DataFrame([Union{Missing, Int}[1]], [:x]), DataFrame([[1]], [:x])) @test df == DataFrame([[1, 1]], [:x]) - @test typeof.(columns(df)) == [Vector{Union{Missing, Int}}] + @test typeof.(eachcol(df)) == [Vector{Union{Missing, Int}}] df = vcat(DataFrame([CategoricalArray([1])], [:x]), DataFrame([[1]], [:x])) @test df == DataFrame([[1, 1]], [:x]) @test df[:x] isa Vector{Int} @@ -186,14 +185,14 @@ module TestCat df = vcat(DataFrame([Union{Int, Missing}[1]], [:x]), DataFrame([["1"]], [:x])) @test df == DataFrame([[1, "1"]], [:x]) - @test typeof.(columns(df)) == [Vector{Any}] + @test typeof.(eachcol(df)) == [Vector{Any}] df = vcat(DataFrame([CategoricalArray([1])], [:x]), DataFrame([CategoricalArray(["1"])], [:x])) @test df == DataFrame([[1, "1"]], [:x]) @test df[:x] isa CategoricalVector{Any} df = vcat(DataFrame([trues(1)], [:x]), DataFrame([[false]], [:x])) @test df == DataFrame([[true, false]], [:x]) - @test typeof.(columns(df)) == [Vector{Bool}] + @test typeof.(eachcol(df)) == [Vector{Bool}] end @testset "vcat out of order" begin diff --git a/test/constructors.jl b/test/constructors.jl index 33dab81b74..ff295b9c2f 100644 --- a/test/constructors.jl +++ b/test/constructors.jl @@ -1,7 +1,6 @@ module TestConstructors using Test, DataFrames using DataFrames: Index, _columns, index - using DataFrames: columns const ≅ = isequal # @@ -116,13 +115,13 @@ module TestConstructors @testset "column types" begin df = DataFrame(A = 1:3, B = 2:4, C = 3:5) answer = [Array{Int,1}, Array{Int,1}, Array{Int,1}] - @test map(typeof, columns(df)) == answer + @test map(typeof, eachcol(df)) == answer df[:D] = [4, 5, missing] push!(answer, Vector{Union{Int, Missing}}) - @test map(typeof, columns(df)) == answer + @test map(typeof, eachcol(df)) == answer df[:E] = 'c' push!(answer, Vector{Char}) - @test map(typeof, columns(df)) == answer + @test map(typeof, eachcol(df)) == answer end @testset "categorical constructor" begin diff --git a/test/dataframe.jl b/test/dataframe.jl index e79a3e12cb..eb756b3ada 100644 --- a/test/dataframe.jl +++ b/test/dataframe.jl @@ -1,7 +1,6 @@ module TestDataFrame using Dates, DataFrames, LinearAlgebra, Statistics, Random, Test using DataFrames: _columns - using DataFrames: columns const ≅ = isequal const ≇ = !isequal @@ -73,7 +72,7 @@ module TestDataFrame c = CategoricalArray{Union{Float64, Missing}}(undef, 2)) # https://github.com/JuliaData/Missings.jl/issues/66 # @test missingdf ≅ similar(df, 2) - @test typeof.(columns(similar(df, 2))) == typeof.(columns(missingdf)) + @test typeof.(eachcol(similar(df, 2))) == typeof.(eachcol(missingdf)) @test size(similar(df, 2)) == size(missingdf) end @@ -81,12 +80,12 @@ module TestDataFrame df = DataFrame(a=[1, 2], b=[3.0, 4.0]) @test haskey(df, :a) @test !haskey(df, :c) - @test get(df, :a, -1) === columns(df)[1] + @test get(df, :a, -1) === eachcol(df)[1] @test get(df, :c, -1) == -1 @test !isempty(df) @test empty!(df) === df - @test isempty(columns(df)) + @test isempty(eachcol(df)) @test isempty(df) @test isempty(DataFrame(a=[], b=[])) @@ -524,11 +523,11 @@ module TestDataFrame df = DataFrame(A = Vector{Union{Int, Missing}}(1:3), B = Vector{Union{Int, Missing}}(4:6)) DRT = CategoricalArrays.DefaultRefType - @test all(c -> isa(c, Vector{Union{Int, Missing}}), columns(categorical!(deepcopy(df)))) + @test all(c -> isa(c, Vector{Union{Int, Missing}}), eachcol(categorical!(deepcopy(df)))) @test all(c -> typeof(c) <: CategoricalVector{Union{Int, Missing}}, - columns(categorical!(deepcopy(df), [1,2]))) + eachcol(categorical!(deepcopy(df), [1,2]))) @test all(c -> typeof(c) <: CategoricalVector{Union{Int, Missing}}, - columns(categorical!(deepcopy(df), [:A,:B]))) + eachcol(categorical!(deepcopy(df), [:A,:B]))) @test findfirst(c -> typeof(c) <: CategoricalVector{Union{Int, Missing}}, _columns(categorical!(deepcopy(df), [:A]))) == 1 @test findfirst(c -> typeof(c) <: CategoricalVector{Union{Int, Missing}}, @@ -561,7 +560,7 @@ module TestDataFrame Union{Int, Missing}[2, 6], Union{Int, Missing}[3, 7], Union{Int, Missing}[4, 8]], [:id, :a, :b, :c, :d]) @test isa(udf[1], Vector{Int}) - @test all(isa.(columns(udf)[2:end], Vector{Union{Int, Missing}})) + @test all(isa.(eachcol(udf)[2:end], Vector{Union{Int, Missing}})) df = DataFrame([categorical(repeat(1:2, inner=4)), categorical(repeat('a':'d', outer=2)), categorical(1:8)], [:id, :variable, :value]) @@ -571,7 +570,7 @@ module TestDataFrame Union{Int, Missing}[2, 6], Union{Int, Missing}[3, 7], Union{Int, Missing}[4, 8]], [:id, :a, :b, :c, :d]) @test isa(udf[1], CategoricalVector{Int}) - @test all(isa.(columns(udf)[2:end], CategoricalVector{Union{Int, Missing}})) + @test all(isa.(eachcol(udf)[2:end], CategoricalVector{Union{Int, Missing}})) end @testset "duplicate entries in unstack warnings" begin @@ -718,14 +717,14 @@ module TestDataFrame df = DataFrame([CategoricalArray(1:10), CategoricalArray(string.('a':'j'))]) allowmissing!(df) - @test all(x->x <: CategoricalVector, typeof.(columns(df))) + @test all(x->x <: CategoricalVector, typeof.(eachcol(df))) @test eltypes(df)[1] <: Union{CategoricalValue{Int}, Missing} @test eltypes(df)[2] <: Union{CategoricalString, Missing} df[1,2] = missing @test_throws MissingException disallowmissing!(df) df[1,2] = "a" disallowmissing!(df) - @test all(x->x <: CategoricalVector, typeof.(columns(df))) + @test all(x->x <: CategoricalVector, typeof.(eachcol(df))) @test eltypes(df)[1] <: CategoricalValue{Int} @test eltypes(df)[2] <: CategoricalString end @@ -735,12 +734,12 @@ module TestDataFrame b = CategoricalArray(["foo"]), c = [0.0], d = CategoricalArray([0.0])) - @test typeof.(columns(similar(df))) == typeof.(columns(df)) + @test typeof.(eachcol(similar(df))) == typeof.(eachcol(df)) @test size(similar(df)) == size(df) rows = size(df, 1) + 5 @test size(similar(df, rows)) == (rows, size(df, 2)) - @test typeof.(columns(similar(df, rows))) == typeof.(columns(df)) + @test typeof.(eachcol(similar(df, rows))) == typeof.(eachcol(df)) e = @test_throws ArgumentError similar(df, -1) @test e.value.msg == "the number of rows must be positive" diff --git a/test/dataframerow.jl b/test/dataframerow.jl index 0ae2244a34..b02eb9606b 100644 --- a/test/dataframerow.jl +++ b/test/dataframerow.jl @@ -1,6 +1,5 @@ module TestDataFrameRow using Test, DataFrames - using DataFrames: columns df = DataFrame(a=Union{Int, Missing}[1, 2, 3, 1, 2, 2], b=[2.0, missing, 1.2, 2.0, missing, missing], @@ -46,7 +45,7 @@ module TestDataFrameRow @test hash(DataFrameRow(df, 2)) != hash(DataFrameRow(df, 6)) # check that hashrows() function generates the same hashes as DataFrameRow - df_rowhashes, _ = DataFrames.hashrows(Tuple(columns(df)), false) + df_rowhashes, _ = DataFrames.hashrows(Tuple(eachcol(df)), false) @test df_rowhashes == [hash(dr) for dr in eachrow(df)] # test incompatible frames diff --git a/test/iteration.jl b/test/iteration.jl index c83a3ef9e1..e137369d9f 100644 --- a/test/iteration.jl +++ b/test/iteration.jl @@ -1,6 +1,5 @@ module TestIteration using Test, DataFrames - using DataFrames: columns df = DataFrame(A = Vector{Union{Int, Missing}}(1:2), B = Vector{Union{Int, Missing}}(2:3)) @@ -15,40 +14,30 @@ module TestIteration @test collect(pairs(row)) isa Vector{Pair{Symbol, Int}} end - # TODO - clean up redundant tests after deprecation @test size(eachcol(df)) == (size(df, 2),) @test size(eachcol(df, true)) == (size(df, 2),) - @test size(columns(df)) == (size(df, 2),) @test size(eachcol(df, false)) == (size(df, 2),) @test length(eachcol(df)) == size(df, 2) @test length(eachcol(df, true)) == size(df, 2) - @test length(columns(df)) == size(df, 2) @test length(eachcol(df, false)) == size(df, 2) - @test eachcol(df)[1] == df[1] # this will be (:A => df[1]) after deprecation + @test eachcol(df)[1] == df[1] @test eachcol(df, true)[1] == df[1] # this will be (:A => df[1]) after deprecation - @test columns(df)[1] == df[1] @test eachcol(df, false)[1] == df[1] - @test collect(eachcol(df)) isa Vector{Pair{Symbol, AbstractVector}} + @test collect(eachcol(df)) isa Vector{AbstractVector} @test collect(eachcol(df, true)) isa Vector{Pair{Symbol, AbstractVector}} - @test collect(eachcol(df)) == [:A => [1, 2], :B => [2, 3]] + @test collect(eachcol(df)) == [[1, 2], [2, 3]] @test collect(eachcol(df, true)) == [:A => [1, 2], :B => [2, 3]] - @test collect(columns(df)) isa Vector{AbstractVector} @test collect(eachcol(df, false)) isa Vector{AbstractVector} - @test collect(columns(df)) == [[1, 2], [2, 3]] @test collect(eachcol(df, false)) == [[1, 2], [2, 3]] - @test eltype(eachcol(df)) == Pair{Symbol, AbstractVector} + @test eltype(eachcol(df)) == AbstractVector @test eltype(eachcol(df, true)) == Pair{Symbol, AbstractVector} - @test eltype(columns(df)) == AbstractVector @test eltype(eachcol(df, false)) == AbstractVector for col in eachcol(df) - @test typeof(col) <: Pair{Symbol, <:AbstractVector} + @test typeof(col) <: AbstractVector end for col in eachcol(df, true) @test typeof(col) <: Pair{Symbol, <:AbstractVector} end - for col in columns(df) - @test isa(col, AbstractVector) - end for col in eachcol(df, false) @test isa(col, AbstractVector) end @@ -56,14 +45,12 @@ module TestIteration @test map(x -> minimum(convert(Array, x)), eachrow(df)) == [1,2] @test map(Vector, eachrow(df)) == [[1, 2], [2, 3]] @test mapcols(minimum, df) == DataFrame(A = [1], B = [2]) - @test map(minimum, eachcol(df)) == DataFrame(A = [1], B = [2]) # this is deprecated + @test map(minimum, eachcol(df)) == [1, 2] @test map(minimum, eachcol(df, true)) == DataFrame(A = [1], B = [2]) # this is deprecated - @test map(minimum, columns(df)) == [1, 2] @test map(minimum, eachcol(df, false)) == [1, 2] @test eltypes(mapcols(Vector{Float64}, df)) == [Float64, Float64] - @test eltypes(map(Vector{Float64}, eachcol(df))) == [Float64, Float64] # this is deprecated + @test eltype(map(Vector{Float64}, eachcol(df))) == Vector{Float64} @test eltypes(map(Vector{Float64}, eachcol(df, true))) == [Float64, Float64] # this is deprecated - @test eltype(map(Vector{Float64}, columns(df))) == Vector{Float64} @test eltype(map(Vector{Float64}, eachcol(df, false))) == Vector{Float64} # test mapcols corner cases diff --git a/test/join.jl b/test/join.jl index 4f6ea9da47..b86971614e 100644 --- a/test/join.jl +++ b/test/join.jl @@ -1,7 +1,6 @@ module TestJoin using Test, DataFrames using DataFrames: similar_missing - using DataFrames: columns const ≅ = isequal name = DataFrame(ID = Union{Int, Missing}[1, 2, 3], @@ -170,7 +169,7 @@ module TestJoin repeat([0, 1, 2, 3, 4], outer = 3), repeat([0, 1, 2, 3, 4], outer = 3)], [:id, :fid, :id_1, :fid_1]) - @test typeof.(columns(join(df1, df2, kind=:cross, makeunique=true))) == + @test typeof.(eachcol(join(df1, df2, kind=:cross, makeunique=true))) == [Vector{Int}, Vector{Float64}, Vector{Int}, Vector{Float64}] i(on) = join(df1, df2, on = on, kind = :inner, makeunique=true) @@ -183,63 +182,63 @@ module TestJoin @test s(:id) == s(:fid) == s([:id, :fid]) == DataFrame([[1, 3], [1, 3]], [:id, :fid]) - @test typeof.(columns(s(:id))) == - typeof.(columns(s(:fid))) == - typeof.(columns(s([:id, :fid]))) == [Vector{Int}, Vector{Float64}] + @test typeof.(eachcol(s(:id))) == + typeof.(eachcol(s(:fid))) == + typeof.(eachcol(s([:id, :fid]))) == [Vector{Int}, Vector{Float64}] @test a(:id) == a(:fid) == a([:id, :fid]) == DataFrame([[5], [5]], [:id, :fid]) - @test typeof.(columns(a(:id))) == - typeof.(columns(a(:fid))) == - typeof.(columns(a([:id, :fid]))) == [Vector{Int}, Vector{Float64}] + @test typeof.(eachcol(a(:id))) == + typeof.(eachcol(a(:fid))) == + typeof.(eachcol(a([:id, :fid]))) == [Vector{Int}, Vector{Float64}] on = :id @test i(on) == DataFrame([[1, 3], [1, 3], [1, 3]], [:id, :fid, :fid_1]) - @test typeof.(columns(i(on))) == [Vector{Int}, Vector{Float64}, Vector{Float64}] + @test typeof.(eachcol(i(on))) == [Vector{Int}, Vector{Float64}, Vector{Float64}] @test l(on) ≅ DataFrame(id = [1, 3, 5], fid = [1, 3, 5], fid_1 = [1, 3, missing]) - @test typeof.(columns(l(on))) == + @test typeof.(eachcol(l(on))) == [Vector{Int}, Vector{Float64}, Vector{Union{Float64, Missing}}] @test r(on) ≅ DataFrame(id = [1, 3, 0, 2, 4], fid = [1, 3, missing, missing, missing], fid_1 = [1, 3, 0, 2, 4]) - @test typeof.(columns(r(on))) == + @test typeof.(eachcol(r(on))) == [Vector{Int}, Vector{Union{Float64, Missing}}, Vector{Float64}] @test o(on) ≅ DataFrame(id = [1, 3, 5, 0, 2, 4], fid = [1, 3, 5, missing, missing, missing], fid_1 = [1, 3, missing, 0, 2, 4]) - @test typeof.(columns(o(on))) == + @test typeof.(eachcol(o(on))) == [Vector{Int}, Vector{Union{Float64, Missing}}, Vector{Union{Float64, Missing}}] on = :fid @test i(on) == DataFrame([[1, 3], [1.0, 3.0], [1, 3]], [:id, :fid, :id_1]) - @test typeof.(columns(i(on))) == [Vector{Int}, Vector{Float64}, Vector{Int}] + @test typeof.(eachcol(i(on))) == [Vector{Int}, Vector{Float64}, Vector{Int}] @test l(on) ≅ DataFrame(id = [1, 3, 5], fid = [1, 3, 5], id_1 = [1, 3, missing]) - @test typeof.(columns(l(on))) == [Vector{Int}, Vector{Float64}, + @test typeof.(eachcol(l(on))) == [Vector{Int}, Vector{Float64}, Vector{Union{Int, Missing}}] @test r(on) ≅ DataFrame(id = [1, 3, missing, missing, missing], fid = [1, 3, 0, 2, 4], id_1 = [1, 3, 0, 2, 4]) - @test typeof.(columns(r(on))) == [Vector{Union{Int, Missing}}, Vector{Float64}, + @test typeof.(eachcol(r(on))) == [Vector{Union{Int, Missing}}, Vector{Float64}, Vector{Int}] @test o(on) ≅ DataFrame(id = [1, 3, 5, missing, missing, missing], fid = [1, 3, 5, 0, 2, 4], id_1 = [1, 3, missing, 0, 2, 4]) - @test typeof.(columns(o(on))) == [Vector{Union{Int, Missing}}, Vector{Float64}, + @test typeof.(eachcol(o(on))) == [Vector{Union{Int, Missing}}, Vector{Float64}, Vector{Union{Int, Missing}}] on = [:id, :fid] @test i(on) == DataFrame([[1, 3], [1, 3]], [:id, :fid]) - @test typeof.(columns(i(on))) == [Vector{Int}, Vector{Float64}] + @test typeof.(eachcol(i(on))) == [Vector{Int}, Vector{Float64}] @test l(on) == DataFrame(id = [1, 3, 5], fid = [1, 3, 5]) - @test typeof.(columns(l(on))) == [Vector{Int}, Vector{Float64}] + @test typeof.(eachcol(l(on))) == [Vector{Int}, Vector{Float64}] @test r(on) == DataFrame(id = [1, 3, 0, 2, 4], fid = [1, 3, 0, 2, 4]) - @test typeof.(columns(r(on))) == [Vector{Int}, Vector{Float64}] + @test typeof.(eachcol(r(on))) == [Vector{Int}, Vector{Float64}] @test o(on) == DataFrame(id = [1, 3, 5, 0, 2, 4], fid = [1, 3, 5, 0, 2, 4]) - @test typeof.(columns(o(on))) == [Vector{Int}, Vector{Float64}] + @test typeof.(eachcol(o(on))) == [Vector{Int}, Vector{Float64}] end @testset "all joins with CategoricalArrays" begin @@ -254,7 +253,7 @@ module TestJoin repeat([0, 1, 2, 3, 4], outer = 3), repeat([0, 1, 2, 3, 4], outer = 3)], [:id, :fid, :id_1, :fid_1]) - @test all(isa.(columns(join(df1, df2, kind=:cross, makeunique=true)), + @test all(isa.(eachcol(join(df1, df2, kind=:cross, makeunique=true)), [CategoricalVector{T} for T in (Int, Float64, Int, Float64)])) i(on) = join(df1, df2, on = on, kind = :inner, makeunique=true) @@ -267,76 +266,76 @@ module TestJoin @test s(:id) == s(:fid) == s([:id, :fid]) == DataFrame([[1, 3], [1, 3]], [:id, :fid]) - @test typeof.(columns(s(:id))) == - typeof.(columns(s(:fid))) == - typeof.(columns(s([:id, :fid]))) - @test all(isa.(columns(s(:id)), + @test typeof.(eachcol(s(:id))) == + typeof.(eachcol(s(:fid))) == + typeof.(eachcol(s([:id, :fid]))) + @test all(isa.(eachcol(s(:id)), [CategoricalVector{T} for T in (Int, Float64)])) @test a(:id) == a(:fid) == a([:id, :fid]) == DataFrame([[5], [5]], [:id, :fid]) - @test typeof.(columns(a(:id))) == - typeof.(columns(a(:fid))) == - typeof.(columns(a([:id, :fid]))) - @test all(isa.(columns(a(:id)), + @test typeof.(eachcol(a(:id))) == + typeof.(eachcol(a(:fid))) == + typeof.(eachcol(a([:id, :fid]))) + @test all(isa.(eachcol(a(:id)), [CategoricalVector{T} for T in (Int, Float64)])) on = :id @test i(on) == DataFrame([[1, 3], [1, 3], [1, 3]], [:id, :fid, :fid_1]) - @test all(isa.(columns(i(on)), + @test all(isa.(eachcol(i(on)), [CategoricalVector{T} for T in (Int, Float64, Float64)])) @test l(on) ≅ DataFrame(id = [1, 3, 5], fid = [1, 3, 5], fid_1 = [1, 3, missing]) - @test all(isa.(columns(l(on)), + @test all(isa.(eachcol(l(on)), [CategoricalVector{T} for T in (Int,Float64,Union{Float64, Missing})])) @test r(on) ≅ DataFrame(id = [1, 3, 0, 2, 4], fid = [1, 3, missing, missing, missing], fid_1 = [1, 3, 0, 2, 4]) - @test all(isa.(columns(r(on)), + @test all(isa.(eachcol(r(on)), [CategoricalVector{T} for T in (Int,Union{Float64, Missing},Float64)])) @test o(on) ≅ DataFrame(id = [1, 3, 5, 0, 2, 4], fid = [1, 3, 5, missing, missing, missing], fid_1 = [1, 3, missing, 0, 2, 4]) - @test all(isa.(columns(o(on)), + @test all(isa.(eachcol(o(on)), [CategoricalVector{T} for T in (Int,Union{Float64,Missing},Union{Float64, Missing})])) on = :fid @test i(on) == DataFrame([[1, 3], [1.0, 3.0], [1, 3]], [:id, :fid, :id_1]) - @test all(isa.(columns(i(on)), + @test all(isa.(eachcol(i(on)), [CategoricalVector{T} for T in (Int, Float64, Int)])) @test l(on) ≅ DataFrame(id = [1, 3, 5], fid = [1, 3, 5], id_1 = [1, 3, missing]) - @test all(isa.(columns(l(on)), + @test all(isa.(eachcol(l(on)), [CategoricalVector{T} for T in (Int, Float64, Union{Int, Missing})])) @test r(on) ≅ DataFrame(id = [1, 3, missing, missing, missing], fid = [1, 3, 0, 2, 4], id_1 = [1, 3, 0, 2, 4]) - @test all(isa.(columns(r(on)), + @test all(isa.(eachcol(r(on)), [CategoricalVector{T} for T in (Union{Int, Missing}, Float64, Int)])) @test o(on) ≅ DataFrame(id = [1, 3, 5, missing, missing, missing], fid = [1, 3, 5, 0, 2, 4], id_1 = [1, 3, missing, 0, 2, 4]) - @test all(isa.(columns(o(on)), + @test all(isa.(eachcol(o(on)), [CategoricalVector{T} for T in (Union{Int, Missing}, Float64, Union{Int, Missing})])) on = [:id, :fid] @test i(on) == DataFrame([[1, 3], [1, 3]], [:id, :fid]) - @test all(isa.(columns(i(on)), + @test all(isa.(eachcol(i(on)), [CategoricalVector{T} for T in (Int, Float64)])) @test l(on) == DataFrame(id = [1, 3, 5], fid = [1, 3, 5]) - @test all(isa.(columns(l(on)), + @test all(isa.(eachcol(l(on)), [CategoricalVector{T} for T in (Int, Float64)])) @test r(on) == DataFrame(id = [1, 3, 0, 2, 4], fid = [1, 3, 0, 2, 4]) - @test all(isa.(columns(r(on)), + @test all(isa.(eachcol(r(on)), [CategoricalVector{T} for T in (Int, Float64)])) @test o(on) == DataFrame(id = [1, 3, 5, 0, 2, 4], fid = [1, 3, 5, 0, 2, 4]) - @test all(isa.(columns(o(on)), + @test all(isa.(eachcol(o(on)), [CategoricalVector{T} for T in (Int, Float64)])) end