Skip to content
This repository was archived by the owner on Mar 11, 2022. It is now read-only.

Commit a2bce2b

Browse files
authored
Return example data as VecColumnTable with Vector columns (#29)
1 parent 7ccedad commit a2bce2b

File tree

7 files changed

+17
-9
lines changed

7 files changed

+17
-9
lines changed

src/DiffinDiffsBase.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ export cb,
133133
lincom,
134134
rescale
135135

136+
include("tables.jl")
136137
include("utils.jl")
137138
include("time.jl")
138-
include("tables.jl")
139139
include("ScaledArrays.jl")
140140
include("treatments.jl")
141141
include("parallels.jl")

src/StatsProcedures.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ function show(io::IO, ::MIME"text/plain", sp::StatsSpec{T}) where T
436436
_show_args(io, sp)
437437
end
438438

439-
function _count!(objcount::IdDict, obj)
439+
function _count!(objcount::AbstractDict, obj)
440440
count = get(objcount, obj, 0)
441441
objcount[obj] = count + 1
442442
end

src/operations.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ end
1111
function _refs_pool(col::AbstractArray, reftype::Type{<:Integer}=UInt32)
1212
refs = refarray(col)
1313
pool = refpool(col)
14-
labeled = pool !== nothing
14+
labeled = pool !== nothing && !(pool isa RotatingTimeRange)
1515
if !labeled
1616
refs, invpool, pool = _label(col, eltype(col), reftype)
1717
end

src/utils.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,13 @@ function exampledata(name::Union{Symbol,String})
144144
Symbol(name) in exampledata() ||
145145
throw(ArgumentError("example dataset $(name) does not exist"))
146146
path = (@__DIR__)*"/../data/$(name).csv.gz"
147-
return open(path) |> GzipDecompressorStream |> read |> CSV.File
147+
cols = open(path) |> GzipDecompressorStream |> read |> CSV.File |> VecColumnTable
148+
# Avoid customized index type for columns from CSV.File
149+
for i in 1:ncol(cols)
150+
col = _columns(cols)[i]
151+
_columns(cols)[i] = convert(Vector, col)
152+
end
153+
return cols
148154
end
149155

150156
# Check whether the input data is a column table

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ import DiffinDiffsBase: required, valid_didargs, result
2323
include("testutils.jl")
2424

2525
const tests = [
26+
"tables",
2627
"utils",
2728
"time",
28-
"tables",
2929
"ScaledArrays",
3030
"terms",
3131
"treatments",

test/tables.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@testset "VecColumnTable" begin
2-
hrs = exampledata("hrs")
2+
hrs = DataFrame(exampledata("hrs"))
33
cols = VecColumnTable(AbstractVector[], Symbol[], Dict{Symbol,Int}())
44
cols1 = VecColumnTable(AbstractVector[], Symbol[])
55
@test cols1 == cols

test/utils.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ end
2323

2424
@testset "exampledata" begin
2525
@test exampledata() == (:hrs, :nsw, :mpdta)
26-
@test size(exampledata(:hrs)) == (3280,)
27-
@test size(exampledata(:nsw)) == (32834,)
28-
@test size(exampledata(:mpdta)) == (2500,)
26+
hrs = exampledata("hrs")
27+
@test size(hrs) == (3280, 11)
28+
@test hrs[1] isa Vector
29+
@test size(exampledata(:nsw)) == (32834, 11)
30+
@test size(exampledata(:mpdta)) == (2500, 5)
2931
end
3032

3133
@testset "checktable" begin

0 commit comments

Comments
 (0)