diff --git a/src/CSV.jl b/src/CSV.jl index 4be9ad61..60a97c87 100644 --- a/src/CSV.jl +++ b/src/CSV.jl @@ -44,6 +44,8 @@ function read(source, sink=nothing; copycols::Bool=false, kwargs...) Tables.CopiedColumns(CSV.File(source; kwargs...)) |> sink end +DataFrames.DataFrame(f::CSV.File; copycols::Bool=true) = DataFrame(getcolumns(f), getnames(f); copycols=copycols) + include("precompile.jl") _precompile_() diff --git a/test/basics.jl b/test/basics.jl index 0cbd7282..7fa5f861 100644 --- a/test/basics.jl +++ b/test/basics.jl @@ -525,4 +525,10 @@ f = CSV.File(transcode(GzipDecompressor, Mmap.mmap(joinpath(dir, "randoms.csv.gz @test length(f) == 70000 @test eltype(f.first) == String +# 702 +f = CSV.File(IOBuffer("a,b,c")) +df = DataFrame(f) +@test names(df) == ["a", "b", "c"] +@test size(df, 1) == 0 + end diff --git a/test/runtests.jl b/test/runtests.jl index 41cb1f55..01587be8 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,4 +1,4 @@ -using Test, CSV, Mmap, Dates, Tables, CategoricalArrays, PooledArrays, CodecZlib, FilePathsBase, SentinelArrays, Parsers +using Test, CSV, Mmap, DataFrames, Dates, Tables, CategoricalArrays, PooledArrays, CodecZlib, FilePathsBase, SentinelArrays, Parsers const dir = joinpath(dirname(pathof(CSV)), "..", "test", "testfiles")