From 85835886174eddd7132f9e59736138f532b44c06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Thu, 25 Mar 2021 11:57:52 +0100 Subject: [PATCH 1/3] clean up outstanding convert --- src/abstractdataframe/abstractdataframe.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/abstractdataframe/abstractdataframe.jl b/src/abstractdataframe/abstractdataframe.jl index a2346cbec7..d7623b8429 100644 --- a/src/abstractdataframe/abstractdataframe.jl +++ b/src/abstractdataframe/abstractdataframe.jl @@ -1144,7 +1144,7 @@ _filter!_helper_astable(df::AbstractDataFrame, nti::Tables.NamedTupleIterator, f function Base.Matrix(df::AbstractDataFrame) T = reduce(promote_type, (eltype(v) for v in eachcol(df))) - return convert(Matrix{T}, df) + return Matrix{T}(df) end function Base.Matrix{T}(df::AbstractDataFrame) where T From 082b90c576d4411572ed82ae0363c8b5fb5cced8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Thu, 25 Mar 2021 12:16:56 +0100 Subject: [PATCH 2/3] Update dataframerow.jl --- src/dataframerow/dataframerow.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dataframerow/dataframerow.jl b/src/dataframerow/dataframerow.jl index 6d5a64c3da..439a6ac624 100644 --- a/src/dataframerow/dataframerow.jl +++ b/src/dataframerow/dataframerow.jl @@ -403,7 +403,7 @@ Base.IteratorEltype(::Type{<:DataFrameRow}) = Base.EltypeUnknown() function Base.Vector(dfr::DataFrameRow) df = parent(dfr) T = reduce(promote_type, (eltype(df[!, i]) for i in parentcols(index(dfr)))) - convert(Vector{T}, dfr) + return Vector{T}(dfr) end Base.Vector{T}(dfr::DataFrameRow) where T = T[dfr[i] for i in 1:length(dfr)] From 871926247bb8ae1b73fd84456eb4d7e2616d8951 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Thu, 25 Mar 2021 12:35:57 +0100 Subject: [PATCH 3/3] fix deprecated tests --- test/dataframerow.jl | 5 ----- test/deprecated.jl | 13 +++++++++++++ test/iteration.jl | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/test/dataframerow.jl b/test/dataframerow.jl index 7775a79089..9c48d440be 100644 --- a/test/dataframerow.jl +++ b/test/dataframerow.jl @@ -279,13 +279,9 @@ end nt = first(Tables.namedtupleiterator(df)) @test copy(dfr) === nt === NamedTuple{(:a, :b), Tuple{Union{Missing, Int}, Float64}}((1, 2.0)) @test sum(skipmissing(copy(df[3, :]))) == 0 - @test convert(Vector, dfr)::Vector{Union{Float64, Missing}} == [1.0, 2.0] - @test convert(Vector{Int}, dfr)::Vector{Int} == [1, 2] @test Vector(dfr)::Vector{Union{Float64, Missing}} == [1.0, 2.0] @test Vector{Int}(dfr)::Vector{Int} == [1, 2] - @test convert(Array, dfr)::Vector{Union{Float64, Missing}} == [1.0, 2.0] - @test convert(Array{Int}, dfr)::Vector{Int} == [1, 2] @test Array(dfr)::Vector{Union{Float64, Missing}} == [1.0, 2.0] @test Array{Int}(dfr)::Vector{Int} == [1, 2] @@ -297,7 +293,6 @@ end dfr2 = DataFrame(c=3, d=4)[1, :] @test NamedTuple(dfr) == (a=1, b=2) @test convert(NamedTuple, dfr) == (a=1, b=2) - @test convert(Tuple, dfr) == (1, 2) @test merge(dfr) == (a=1, b=2) @test merge(dfr, (c=3, d=4)) == (a=1, b=2, c=3, d=4) @test merge((c=3, d=4), dfr) == (c=3, d=4, a=1, b=2) diff --git a/test/deprecated.jl b/test/deprecated.jl index 8b6594c8c4..22fc5860a9 100644 --- a/test/deprecated.jl +++ b/test/deprecated.jl @@ -241,4 +241,17 @@ end @test convert(Tuple, key) isa Tuple{Int} end +@testset "DataFrameRow convert" begin + df = DataFrame(a=[1, missing, missing], b=[2.0, 3.0, 0.0]) + dfr = DataFrameRow(df, 1, :) + @test convert(Vector, dfr)::Vector{Union{Float64, Missing}} == [1.0, 2.0] + @test convert(Vector{Int}, dfr)::Vector{Int} == [1, 2] + @test convert(Array, dfr)::Vector{Union{Float64, Missing}} == [1.0, 2.0] + @test convert(Array{Int}, dfr)::Vector{Int} == [1, 2] + + dfr = DataFrame(a=1, b=2)[1, :] + dfr2 = DataFrame(c=3, d=4)[1, :] + @test convert(Tuple, dfr) == (1, 2) +end + end # module diff --git a/test/iteration.jl b/test/iteration.jl index 29130b101b..3e47eb40a1 100644 --- a/test/iteration.jl +++ b/test/iteration.jl @@ -47,7 +47,7 @@ using Test, DataFrames @test isa(col, AbstractVector) end - @test map(x -> minimum(convert(Vector, x)), eachrow(df)) == [1, 2] + @test map(x -> minimum(Vector(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)) == [1, 2]