Skip to content

Commit

Permalink
Fix DataFrame(CSV.File(...)) with header-only
Browse files Browse the repository at this point in the history
  • Loading branch information
omus committed Jul 31, 2020
1 parent ca98974 commit 612ee1b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/CSV.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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_()

Expand Down
6 changes: 6 additions & 0 deletions test/basics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -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")

Expand Down

0 comments on commit 612ee1b

Please sign in to comment.