From d8bbcb1ba4227bedb8c05c448098e395a1d50059 Mon Sep 17 00:00:00 2001 From: David Anthoff Date: Fri, 3 Aug 2018 15:35:06 -0700 Subject: [PATCH 1/2] Update to julia 0.7 --- .travis.yml | 3 ++- LICENSE.md | 2 +- NEWS.md | 3 +++ REQUIRE | 2 +- appveyor.yml | 33 ++++++++++++--------------------- src/csv_writer.jl | 37 +++++++++++++++++-------------------- test/runtests.jl | 20 +++++++++++--------- 7 files changed, 47 insertions(+), 53 deletions(-) diff --git a/.travis.yml b/.travis.yml index 58c555b..554c526 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,8 @@ os: - linux - osx julia: - - 0.6 + - 0.7 + - nightly notifications: email: false git: diff --git a/LICENSE.md b/LICENSE.md index d971b66..a14cd42 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ The CSVFiles.jl package is licensed under the MIT "Expat" License: -> Copyright (c) 2017: David Anthoff. +> Copyright (c) 2017-2018: David Anthoff. > > > Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/NEWS.md b/NEWS.md index 93fb344..272ad7f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,6 @@ +# CSVFiles.jl v0.9.0 +* Drop julia 0.6 support, add julia 0.7 support + # CSVFiles.jl v0.8.0 * Add nastring option to save diff --git a/REQUIRE b/REQUIRE index 9c392ba..8098b62 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,4 +1,4 @@ -julia 0.6 +julia 0.7- TextParse 0.4.0 IteratorInterfaceExtensions 0.0.2 TableTraits 0.0.3 diff --git a/appveyor.yml b/appveyor.yml index fd4c9fe..cef7280 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,14 +1,17 @@ environment: matrix: - - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe" - - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe" + - julia_version: 0.7 + - julia_version: latest + +platform: + - x86 + - x64 ## uncomment the following lines to allow failures on nightly julia ## (tests will run but not make your overall status red) #matrix: # allow_failures: -# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe" -# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe" +# - julia_version: latest branches: only: @@ -22,24 +25,12 @@ notifications: on_build_status_changed: false install: - - ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12" -# If there's a newer build queued for the same PR, cancel this one - - ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod ` - https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | ` - Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { ` - throw "There are newer queued builds for this pull request, failing early." } -# Download most recent Julia Windows binary - - ps: (new-object net.webclient).DownloadFile( - $env:JULIA_URL, - "C:\projects\julia-binary.exe") -# Run installer silently, output to C:\projects\julia - - C:\projects\julia-binary.exe /S /D=C:\projects\julia + - ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/master/bin/install.ps1')) build_script: -# Need to convert from shallow to complete for Pkg.clone to work - - IF EXIST .git\shallow (git fetch --unshallow) - - C:\projects\julia\bin\julia -e "versioninfo(); - Pkg.clone(pwd(), \"CSVFiles\"); Pkg.build(\"CSVFiles\")" + - echo "%JL_BUILD_SCRIPT%" + - julia -e "%JL_BUILD_SCRIPT%" test_script: - - C:\projects\julia\bin\julia -e "Pkg.test(\"CSVFiles\")" + - echo "%JL_TEST_SCRIPT%" + - julia -e "%JL_TEST_SCRIPT%" diff --git a/src/csv_writer.jl b/src/csv_writer.jl index ab80a35..35418c4 100644 --- a/src/csv_writer.jl +++ b/src/csv_writer.jl @@ -1,25 +1,24 @@ +function _writevalue(io::IO, value::String, delim, quotechar::Nothing, escapechar, nastring) + print(io, value) +end + function _writevalue(io::IO, value::String, delim, quotechar, escapechar, nastring) - if isnull(quotechar) - print(io, value) - else - quotechar_unpacked = get(quotechar) - print(io, quotechar_unpacked) - for c in value - if c==quotechar_unpacked || c==escapechar - print(io, escapechar) - end - print(io, c) + print(io, quotechar) + for c in value + if c==quotechar || c==escapechar + print(io, escapechar) end - print(io, quotechar_unpacked) + print(io, c) end + print(io, quotechar) end function _writevalue(io::IO, value, delim, quotechar, escapechar, nastring) print(io, value) end -function _writevalue{T}(io::IO, value::DataValue{T}, delim, quotechar, escapechar, nastring) - if isnull(value) +function _writevalue(io::IO, value::DataValue{T}, delim, quotechar, escapechar, nastring) where {T} + if isna(value) print(io, nastring) else _writevalue(io, get(value), delim, quotechar, escapechar, nastring) @@ -27,7 +26,7 @@ function _writevalue{T}(io::IO, value::DataValue{T}, delim, quotechar, escapecha end -@generated function _writecsv{T}(io::IO, it, ::Type{T}, delim, quotechar, escapechar, nastring) +@generated function _writecsv(io::IO, it, ::Type{T}, delim, quotechar, escapechar, nastring) where {T} col_names = fieldnames(T) n = length(col_names) push_exprs = Expr(:block) @@ -50,19 +49,17 @@ function _save(io, data; delim=',', quotechar='"', escapechar='\\', nastring="NA isiterabletable(data) || error("Can't write this data to a CSV file.") it = getiterator(data) - colnames = TableTraits.column_names(it) - - quotechar_internal = quotechar==nothing ? Nullable{Char}() : Nullable{Char}(quotechar) + colnames = collect(eltype(it).parameters[1]) if header - if isnull(quotechar_internal) + if quotechar===nothing join(io,[string(colname) for colname in colnames],delim) else - join(io,["$(quotechar)" *replace(string(colname), quotechar, "$(escapechar)$(quotechar)") * "$(quotechar)" for colname in colnames],delim) + join(io,["$(quotechar)" * replace(string(colname), quotechar => "$(escapechar)$(quotechar)") * "$(quotechar)" for colname in colnames],delim) end println(io) end - _writecsv(io, it, eltype(it), delim, quotechar_internal, escapechar, nastring) + _writecsv(io, it, eltype(it), delim, quotechar, escapechar, nastring) end function _save(filename::AbstractString, data; delim=',', quotechar='"', escapechar='\\', nastring="NA", header=true) diff --git a/test/runtests.jl b/test/runtests.jl index 4e01ea3..734c76b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,14 +1,16 @@ using CSVFiles -using NamedTuples +using IteratorInterfaceExtensions +using TableTraits +using FileIO using DataValues -using Base.Test +using Test @testset "CSVFiles" begin @testset "basic" begin array = collect(load(joinpath(@__DIR__, "data.csv"))) @test length(array) == 3 - @test array == [@NT(Name="John",Age=34.,Children=2),@NT(Name="Sally",Age=54.,Children=1),@NT(Name="Jim",Age=23.,Children=0)] + @test array == [(Name="John",Age=34.,Children=2),(Name="Sally",Age=54.,Children=1),(Name="Jim",Age=23.,Children=0)] output_filename = tempname() * ".csv" @@ -19,7 +21,7 @@ using Base.Test @test array == array2 finally - gc() + GC.gc() rm(output_filename) end end @@ -32,7 +34,7 @@ end end @testset "missing values" begin - array3 = [@NT(a=DataValue(3),b="df\"e"),@NT(a=DataValue{Int}(),b="something")] + array3 = [(a=DataValue(3),b="df\"e"),(a=DataValue{Int}(),b="something")] @testset "default" begin output_filename2 = tempname() * ".csv" @@ -56,7 +58,7 @@ end end @testset "Less Basic" begin - array = [@NT(Name="John",Age=34.,Children=2),@NT(Name="Sally",Age=54.,Children=1),@NT(Name="Jim",Age=23.,Children=0)] + array = [(Name="John",Age=34.,Children=2),(Name="Sally",Age=54.,Children=1),(Name="Jim",Age=23.,Children=0)] @testset "remote loading" begin rem_array = collect(load("https://raw.githubusercontent.com/queryverse/CSVFiles.jl/v0.2.0/test/data.csv")) @test length(rem_array) == 3 @@ -73,7 +75,7 @@ end @test length(array4) == 3 @test array4 == array finally - gc() + GC.gc() rm(output_filename3) end end @@ -86,14 +88,14 @@ end array |> save(output_filename4, quotechar=nothing) finally - gc() + GC.gc() rm(output_filename4) end end end @testset "Streams" begin - data = [@NT(Name="John",Age=34.,Children=2),@NT(Name="Sally",Age=54.,Children=1),@NT(Name="Jim",Age=23.,Children=0)] + data = [(Name="John",Age=34.,Children=2),(Name="Sally",Age=54.,Children=1),(Name="Jim",Age=23.,Children=0)] @testset "CSV" begin stream = IOBuffer() From dea1f1d6507c7e91b0ed5da5a6469d14855c20e3 Mon Sep 17 00:00:00 2001 From: David Anthoff Date: Mon, 6 Aug 2018 10:54:16 -0300 Subject: [PATCH 2/2] Update REQUIRE --- REQUIRE | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/REQUIRE b/REQUIRE index 8098b62..9d454aa 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,10 +1,10 @@ julia 0.7- -TextParse 0.4.0 -IteratorInterfaceExtensions 0.0.2 -TableTraits 0.0.3 -TableTraitsUtils 0.1.3 -DataValues 0.1.0 -FileIO 0.9.0 +TextParse 0.6.0 +IteratorInterfaceExtensions 0.1.0 +TableTraits 0.3.0 +TableTraitsUtils 0.2.0 +DataValues 0.4.2 +FileIO 1.0.0 HTTP 0.6.0 -IterableTables 0.6.1 -TableShowUtils 0.0.1 +IterableTables 0.8.1 +TableShowUtils 0.1.0