Skip to content

Commit 527fa8e

Browse files
authored
Allow constructing Matrix from empty dataframe (#2878)
1 parent 63faa17 commit 527fa8e

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/abstractdataframe/abstractdataframe.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ _filter!_helper_astable(df::AbstractDataFrame, nti::Tables.NamedTupleIterator, f
11581158
delete!(df, _findall((x -> !(f(x)::Bool)).(nti)))
11591159

11601160
function Base.Matrix(df::AbstractDataFrame)
1161-
T = reduce(promote_type, (eltype(v) for v in eachcol(df)))
1161+
T = reduce(promote_type, (eltype(v) for v in eachcol(df)), init=Union{})
11621162
return Matrix{T}(df)
11631163
end
11641164

test/conversions.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const ≅ = isequal
66

77
@testset "Constructors to Base types" begin
88
df = DataFrame()
9+
@test Matrix(df) isa Matrix{Union{}}
10+
@test size(Matrix(df)) == (0, 0)
911
df[!, :A] = 1:5
1012
df[!, :B] = 1.0:5.0
1113
@test isa(Matrix(df), Matrix{Float64})

0 commit comments

Comments
 (0)