Skip to content

Commit

Permalink
Merge pull request #27 from queryverse/julia-0.7
Browse files Browse the repository at this point in the history
Update to julia 0.7
  • Loading branch information
davidanthoff authored Aug 6, 2018
2 parents fdd0bc6 + dea1f1d commit 2c400f1
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 61 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ os:
- linux
- osx
julia:
- 0.6
- 0.7
- nightly
notifications:
email: false
git:
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
18 changes: 9 additions & 9 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
julia 0.6
TextParse 0.4.0
IteratorInterfaceExtensions 0.0.2
TableTraits 0.0.3
TableTraitsUtils 0.1.3
DataValues 0.1.0
FileIO 0.9.0
julia 0.7-
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
33 changes: 12 additions & 21 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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%"
37 changes: 17 additions & 20 deletions src/csv_writer.jl
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
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)
end
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)
Expand All @@ -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)
Expand Down
20 changes: 11 additions & 9 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -19,7 +21,7 @@ using Base.Test

@test array == array2
finally
gc()
GC.gc()
rm(output_filename)
end
end
Expand All @@ -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"
Expand All @@ -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
Expand All @@ -73,7 +75,7 @@ end
@test length(array4) == 3
@test array4 == array
finally
gc()
GC.gc()
rm(output_filename3)
end
end
Expand All @@ -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()
Expand Down

0 comments on commit 2c400f1

Please sign in to comment.