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

Fix DataFrame(CSV.File(...)) with header-only #703

Closed
wants to merge 2 commits into from
Closed
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 Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ DataFrames = "0.21"
FilePathsBase = "0.6,0.7,0.8,0.9"
Parsers = "1"
PooledArrays = "0.5"
Tables = "1"
SentinelArrays = "1.2"
Tables = "1"
WeakRefStrings = "0.5,0.6"
julia = "1"

Expand Down
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 @@ -534,4 +534,10 @@ f = CSV.File(IOBuffer("a,b\n1,2"); types = Dict{Symbol,Type}(
@test f.a[1] == "1"
@test f.b[1] == "2"

# 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