-
Notifications
You must be signed in to change notification settings - Fork 146
Ensure FilePaths work #511
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
Changes from all commits
5738587
851b375
de9e552
ee778f7
863c088
a024a72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -175,27 +175,25 @@ function slurp(source) | |
| return final | ||
| end | ||
|
|
||
| getsource(source::Vector{UInt8}, ::Any) = source | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was just typing this solution up as you pushed your commit. Thank you for making this 100% cleaner and easier to read!! 🚀 💯 |
||
| getsource(source::Cmd, ::Any) = Base.read(source) | ||
| getsource(source::AbstractPath, ::Any) = Base.read(open(source)) | ||
| getsource(source::IO, ::Any) = slurp(source) | ||
| getsource(source::SystemPath, use_mmap) = getsource(string(source), use_mmap) | ||
| function getsource(source, use_mmap) | ||
| if source isa Vector{UInt8} | ||
| return source | ||
| elseif source isa Cmd | ||
| return Base.read(source) | ||
| elseif use_mmap && !isa(source, IO) | ||
| return Mmap.mmap(source) | ||
| elseif !isa(source, IO) | ||
| m = Mmap.mmap(source) | ||
| m2 = Mmap.mmap(Vector{UInt8}, length(m)) | ||
| copyto!(m2, 1, m, 1, length(m)) | ||
| finalize(m) | ||
| return m2 | ||
| else | ||
| return slurp(source isa IO ? source : open(String(source))) | ||
| m = Mmap.mmap(source) | ||
| if use_mmap | ||
| return m | ||
| end | ||
| m2 = Mmap.mmap(Vector{UInt8}, length(m)) | ||
| copyto!(m2, 1, m, 1, length(m)) | ||
| finalize(m) | ||
| return m2 | ||
| end | ||
|
|
||
| getname(buf::Vector{UInt8}) = "<raw buffer>" | ||
| getname(cmd::Cmd) = string(cmd) | ||
| getname(str) = String(str) | ||
| getname(str) = string(str) | ||
| getname(io::I) where {I <: IO} = string("<", I, ">") | ||
|
|
||
| const RESERVED = Set(["local", "global", "export", "let", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,6 +70,11 @@ using CSV, Dates, WeakRefStrings, CategoricalArrays, Tables | |
| @test String(read(file)) == "col1,col2,col3\n1,4,7\n2,5,8\n3,6,9\n" | ||
| rm(file) | ||
|
|
||
| filepath = Path(file) | ||
| (col1=[1,2,3], col2=[4,5,6], col3=[7,8,9]) |> CSV.write(filepath) | ||
| @test String(read(filepath)) == "col1,col2,col3\n1,4,7\n2,5,8\n3,6,9\n" | ||
| rm(filepath) | ||
|
|
||
| open(file, "w") do io | ||
| (col1=[1,2,3], col2=[4,5,6], col3=[7,8,9]) |> CSV.write(io) | ||
| end | ||
|
|
@@ -165,7 +170,7 @@ using CSV, Dates, WeakRefStrings, CategoricalArrays, Tables | |
|
|
||
| # validate char args: #369 | ||
| @test_throws ArgumentError (col1=[1,2,3], col2=[4,5,6], col3=[7,8,9]) |> CSV.write(io; escapechar='☃') | ||
|
|
||
| # custom float decimal: #385 | ||
| (col1=[1.1,2.2,3.3], col2=[4,5,6], col3=[7,8,9]) |> CSV.write(io; delim='\t', decimal=',') | ||
| @test String(take!(io)) == "col1\tcol2\tcol3\n1,1\t4\t7\n2,2\t5\t8\n3,3\t6\t9\n" | ||
|
|
@@ -203,4 +208,9 @@ using CSV, Dates, WeakRefStrings, CategoricalArrays, Tables | |
| (col1=[""],) |> CSV.write(io) | ||
| @test String(take!(io)) == "col1\n\n" | ||
|
|
||
| # test with FilePath | ||
| mktmpdir() do tmp | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just as a heads up: this will be deprecated to
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
| CSV.write(tmp / "test.txt", df) | ||
| @test CSV.read(tmp / "test.txt") == df | ||
| end | ||
| end # @testset "CSV.write" | ||
Uh oh!
There was an error while loading. Please reload this page.