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

clean up outstanding convert #2675

Merged
merged 3 commits into from
Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/abstractdataframe/abstractdataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/dataframerow/dataframerow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
5 changes: 0 additions & 5 deletions test/dataframerow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions test/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/iteration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down