Skip to content

Commit 18f8e51

Browse files
authored
Port to CategoricalArrays 0.8, bump version to 0.6.2 (#602)
The change to `levels!` implies that all reference codes will be updated at the end to match the new order of levels (unless they were already sorted). Require DataFrames 0.21 which is the only version to support CategoricalArrays 0.8. Bump version to 0.6.2
1 parent bc9859d commit 18f8e51

7 files changed

Lines changed: 20 additions & 20 deletions

File tree

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "CSV"
22
uuid = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
33
authors = ["Jacob Quinn <quinn.jacobd@gmail.com>"]
4-
version = "0.6.0"
4+
version = "0.6.2"
55

66
[deps]
77
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
@@ -16,8 +16,8 @@ Unicode = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
1616
WeakRefStrings = "ea10d353-3f73-51f8-a26c-33c1cb351aa5"
1717

1818
[compat]
19-
CategoricalArrays = "0.5,0.6,0.7"
20-
DataFrames = "0.18,0.19,0.20"
19+
CategoricalArrays = "0.8"
20+
DataFrames = "0.21"
2121
FilePathsBase = "0.6,0.7,0.8"
2222
Parsers = "1"
2323
PooledArrays = "0.5"

src/header.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ end
8585
throw(ArgumentError("\"$source\" is not a valid file"))
8686
(types !== nothing && any(x->!isconcretetype(x) && !(x isa Union), types isa AbstractDict ? values(types) : types)) && throw(ArgumentError("Non-concrete types passed in `types` keyword argument, please provide concrete types for columns: $types"))
8787
if type !== nothing && typecode(type) == EMPTY
88-
throw(ArgumentError("$type isn't supported in the `type` keyword argument; must be one of: `Int64`, `Float64`, `Date`, `DateTime`, `Bool`, `Missing`, `PooledString`, `CategoricalString{UInt32}`, or `String`"))
88+
throw(ArgumentError("$type isn't supported in the `type` keyword argument; must be one of: `Int64`, `Float64`, `Date`, `DateTime`, `Bool`, `Missing`, `PooledString`, `CategoricalValue{String, UInt32}`, or `String`"))
8989
elseif types !== nothing && any(x->typecode(x) == EMPTY, types isa AbstractDict ? values(types) : types)
9090
T = nothing
9191
for x in (types isa AbstractDict ? values(types) : types)
@@ -94,7 +94,7 @@ end
9494
break
9595
end
9696
end
97-
throw(ArgumentError("unsupported type $T in the `types` keyword argument; must be one of: `Int64`, `Float64`, `Date`, `DateTime`, `Bool`, `Missing`, `PooledString`, `CategoricalString{UInt32}`, or `String`"))
97+
throw(ArgumentError("unsupported type $T in the `types` keyword argument; must be one of: `Int64`, `Float64`, `Date`, `DateTime`, `Bool`, `Missing`, `PooledString`, `CategoricalValue{String, UInt32}`, or `String`"))
9898
end
9999
checkvaliddelim(delim)
100100
ignorerepeated && delim === nothing && throw(ArgumentError("auto-delimiter detection not supported when `ignorerepeated=true`; please provide delimiter like `delim=','`"))
@@ -199,10 +199,10 @@ end
199199
T = type === nothing ? (streaming ? (STRING | MISSING) : EMPTY) : (typecode(type) | USER)
200200
if types isa Vector
201201
typecodes = TypeCode[typecode(T) | USER for T in types]
202-
categorical = categorical | any(x->x == CategoricalString{UInt32}, types)
202+
categorical = categorical | any(x->x == CategoricalValue{String, UInt32}, types)
203203
elseif types isa AbstractDict
204204
typecodes = initialtypes(T, types, names)
205-
categorical = categorical | any(x->x == CategoricalString{UInt32}, values(types))
205+
categorical = categorical | any(x->x == CategoricalValue{String, UInt32}, values(types))
206206
else
207207
typecodes = TypeCode[T for _ = 1:ncols]
208208
end

src/tables.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ function Base.copy(col::Union{Column{T, S}, Column2{T, S}}) where {T <: Union{St
135135
end
136136
if catg
137137
pool = CategoricalPool(refs)
138-
levels!(pool, sort(levels(pool)))
139138
A = CategoricalArray{T, 1}(values, pool)
139+
levels!(A, sort(levels(A)))
140140
else
141141
A = PooledArray(PooledArrays.RefArray(values), refs)
142142
end

src/utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ typecode(::Type{Time}) = TIME
7474
typecode(::Type{Bool}) = BOOL
7575
typecode(::Type{<:AbstractString}) = STRING
7676
typecode(::Type{PooledString}) = POOL
77-
typecode(::Type{CategoricalString{UInt32}}) = POOL
77+
typecode(::Type{CategoricalValue{String, UInt32}}) = POOL
7878
typecode(::Type{Union{}}) = EMPTY
7979
typecode(::Type{Union{T, Missing}}) where {T} = typecode(T) | MISSING
8080
typecode(::Type{T}) where {T} = EMPTY

src/write.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ end
402402
writecell(buf, pos, len, io, x, opts) =
403403
writecell(buf, pos, len, io, Base.string(x), opts)
404404

405-
writecell(buf, pos, len, io, x::CategoricalString, opts) =
405+
writecell(buf, pos, len, io, x::CategoricalValue{String}, opts) =
406406
writecell(buf, pos, len, io, Base.string(x), opts)
407407

408408
function writecell(buf, pos, len, io, x::AbstractString, opts)

test/basics.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,11 @@ df = CSV.read(IOBuffer("x\na\nb\na\nb\na\nb\na\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nn\
210210

211211
# a few corner cases for escape strings
212212
df = CSV.read(IOBuffer("\"column name with \"\" escape character inside\"\n1\n"))
213-
@test names(df)[1] == Symbol("column name with \" escape character inside")
213+
@test names(df)[1] == "column name with \" escape character inside"
214214

215215
df = CSV.read(IOBuffer("\"column name with \"\" escape character inside\",1\n,2"), transpose=true)
216-
@test names(df)[1] == Symbol("column name with \" escape character inside")
217-
@test names(df)[2] == :Column2
216+
@test names(df)[1] == "column name with \" escape character inside"
217+
@test names(df)[2] == "Column2"
218218

219219
df = CSV.read(IOBuffer("x\na\nb\n\"quoted field with \"\" escape character inside\"\n"), pool=true)
220220
@test df.x[1] == "a"
@@ -241,19 +241,19 @@ df = CSV.read(IOBuffer("x\nabc\n"), type=Int)
241241

242242
# transpose corner cases
243243
df = CSV.read(IOBuffer("x,y,1\nx2,y2,2\n"), transpose=true, header=2)
244-
@test names(df) == [:y, :y2]
244+
@test names(df) == ["y", "y2"]
245245
@test size(df) == (1, 2)
246246
@test df.y[1] == 1
247247
@test df.y2[1] == 2
248248

249249
df = CSV.read(IOBuffer("x,y,1\nx2,y2,2\n"), transpose=true, header=1, datarow=3)
250-
@test names(df) == [:x, :x2]
250+
@test names(df) == ["x", "x2"]
251251
@test size(df) == (1, 2)
252252
@test df.x[1] == 1
253253
@test df.x2[1] == 2
254254

255255
df = CSV.read(IOBuffer("x,y,1\nx2,y2,2\n"), transpose=true, header=false, datarow=3)
256-
@test names(df) == [:Column1, :Column2]
256+
@test names(df) == ["Column1", "Column2"]
257257
@test size(df) == (1, 2)
258258
@test df.Column1[1] == 1
259259
@test df.Column2[1] == 2
@@ -266,7 +266,7 @@ df = CSV.read(IOBuffer(""), transpose=true, header=Symbol[])
266266

267267
# providing empty header vector
268268
df = CSV.read(IOBuffer("x\nabc\n"), header=Symbol[])
269-
@test names(df) == [:Column1]
269+
@test names(df) == ["Column1"]
270270

271271
# Union{Bool, Missing}
272272
df = CSV.read(IOBuffer("x\ntrue\n\n"))
@@ -380,7 +380,7 @@ df = CSV.read(IOBuffer("thistime\n10:00:00.0\n12:00:00.0"))
380380

381381
# 530
382382
df = CSV.read(IOBuffer(",column2\nNA,2\n2,3"), missingstrings=["NA"])
383-
@test names(df) == [:Column1, :column2]
383+
@test names(df) == ["Column1", "column2"]
384384

385385
# reported on slack from Kevin Bonham
386386
df = CSV.read(IOBuffer("x\n01:02:03\n\n04:05:06\n"), delim=',')

test/runtests.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ end # @testset "CSV.File"
2323
include("write.jl")
2424

2525
@testset "CategoricalArray levels (including ordering)" begin
26-
f = CSV.read(IOBuffer("X\nb\nc\na\nc"), types=[CategoricalString{UInt32}], copycols=true)
26+
f = CSV.read(IOBuffer("X\nb\nc\na\nc"), types=[CategoricalValue{String, UInt32}], copycols=true)
2727
v = f.X[1]
2828
@test v == "b"
2929
@test levels(v.pool) == ["a", "b", "c"]
@@ -37,7 +37,7 @@ include("write.jl")
3737
v = f.X[1]
3838
@test v == "b"
3939
@test levels(v.pool) == ["b", "c"]
40-
@test typeof(f.X) == CategoricalArray{Union{Missing, String},1,UInt32,String,CategoricalString{UInt32},Missing}
40+
@test typeof(f.X) == CategoricalArray{Union{Missing, String},1,UInt32,String,CategoricalValue{String, UInt32},Missing}
4141

4242
end
4343

0 commit comments

Comments
 (0)