Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using Documenter, FeatherFiles

makedocs(
modules = [FeatherFiles],
sitename = "FeatherFiles.jl",
modules=[FeatherFiles],
sitename="FeatherFiles.jl",
analytics="UA-132838790-1",
pages = [
pages=[
"Introduction" => "index.md"
]
)

deploydocs(
repo = "github.com/queryverse/FeatherFiles.jl.git"
repo="github.com/queryverse/FeatherFiles.jl.git"
)
8 changes: 4 additions & 4 deletions src/FeatherFiles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ TableTraits.supports_get_columns_copy_using_missing(x::FeatherFile) = true
function IteratorInterfaceExtensions.getiterator(file::FeatherFile)
rs = featherread(file.filename)

for i=1:length(rs.columns)
for i = 1:length(rs.columns)
col_eltype = eltype(rs.columns[i])
if isa(col_eltype, Union) && col_eltype.b <: Missing
T = DataValueArrowVector{col_eltype.a,typeof(rs.columns[i])}
Expand Down Expand Up @@ -70,8 +70,8 @@ end
# end

function TableTraits.get_columns_copy_using_missing(file::FeatherFile)
rs = featherread(file.filename)
return NamedTuple{(Symbol.(rs.names)...,)}(((convert(Vector{eltype(c)}, c) for c in rs.columns)...,))
rs = featherread(file.filename)
return NamedTuple{(Symbol.(rs.names)...,)}(((convert(Vector{eltype(c)}, c) for c in rs.columns)...,))
end

function fileio_save(f::FileIO.File{FileIO.format"Feather"}, data)
Expand All @@ -81,7 +81,7 @@ function fileio_save(f::FileIO.File{FileIO.format"Feather"}, data)

columns = Any[c for c in columns]

for i=1:length(columns)
for i = 1:length(columns)
if eltype(columns[i]) <: DataValue
T = MissingDataValueVector{eltype(eltype(columns[i])),typeof(columns[i])}
columns[i] = T(columns[i])
Expand Down
8 changes: 4 additions & 4 deletions src/missing-conversion.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
struct DataValueArrowVector{J,T<:Arrow.ArrowVector{Union{J,Missing}}} <: AbstractVector{DataValue{J}}
struct DataValueArrowVector{J,T <: Arrow.ArrowVector{Union{J,Missing}}} <: AbstractVector{DataValue{J}}
data::T
end

Expand All @@ -10,17 +10,17 @@ Base.size(A::DataValueArrowVector) = size(A.data)
o
end

@inline function Base.getindex(A::DataValueArrowVector{J,T}, i) where {J,T<:Arrow.DictEncoding{Union{Missing,J}}}
@inline function Base.getindex(A::DataValueArrowVector{J,T}, i) where {J,T <: Arrow.DictEncoding{Union{Missing,J}}}
@boundscheck checkbounds(A.data, i)
@inbounds o = Arrow.unsafe_isnull(A.data, i) ? DataValue{J}() : DataValue{J}(A.data.pool[A.data.refs[i]+1])
@inbounds o = Arrow.unsafe_isnull(A.data, i) ? DataValue{J}() : DataValue{J}(A.data.pool[A.data.refs[i] + 1])
o
end

Base.IndexStyle(::Type{<:DataValueArrowVector}) = IndexLinear()

Base.eltype(::Type{DataValueArrowVector{J,T}}) where {J,T} = DataValue{J}

struct MissingDataValueVector{J,T<:AbstractVector{DataValue{J}}} <: AbstractVector{Union{J,Missing}}
struct MissingDataValueVector{J,T <: AbstractVector{DataValue{J}}} <: AbstractVector{Union{J,Missing}}
data::T
end

Expand Down
46 changes: 23 additions & 23 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,35 @@ using QueryTables

@testset "FeatherFiles" begin

source = [(Name="John", Age=34., Children=2),
(Name="Sally", Age=54., Children=1),
(Name="Jim", Age=34., Children=0)]
source = [(Name = "John", Age = 34., Children = 2),
(Name = "Sally", Age = 54., Children = 1),
(Name = "Jim", Age = 34., Children = 0)]

output_filename = tempname() * ".feather"
output_filename = tempname() * ".feather"

source |> save(output_filename)
source |> save(output_filename)

try
sink = load(output_filename) |> IteratorInterfaceExtensions.getiterator |> collect
try
sink = load(output_filename) |> IteratorInterfaceExtensions.getiterator |> collect

@test source == sink
@test source == sink

featherfile = load(output_filename)
featherfile = load(output_filename)

@test IteratorInterfaceExtensions.isiterable(featherfile) == true
@test TableTraits.isiterabletable(featherfile) == true
@test TableTraits.supports_get_columns_copy_using_missing(featherfile) == true
ff_as_cols = TableTraits.get_columns_copy_using_missing(featherfile)
@test ff_as_cols == (Name=["John", "Sally", "Jim"], Age=[34., 54., 34.], Children=[2,1,0])
finally
@test IteratorInterfaceExtensions.isiterable(featherfile) == true
@test TableTraits.isiterabletable(featherfile) == true
@test TableTraits.supports_get_columns_copy_using_missing(featherfile) == true
ff_as_cols = TableTraits.get_columns_copy_using_missing(featherfile)
@test ff_as_cols == (Name = ["John", "Sally", "Jim"], Age = [34., 54., 34.], Children = [2,1,0])
finally
GC.gc()
GC.gc()
# rm(output_filename)
end

source2 = [(Name=DataValue("John"), Age=DataValue(34.), Children=DataValue{Int}()),
(Name=DataValue("Sally"), Age=DataValue{Float64}(), Children=DataValue(1)),
(Name=DataValue{String}(), Age=DataValue(34.), Children=DataValue(0))]
source2 = [(Name = DataValue("John"), Age = DataValue(34.), Children = DataValue{Int}()),
(Name = DataValue("Sally"), Age = DataValue{Float64}(), Children = DataValue(1)),
(Name = DataValue{String}(), Age = DataValue(34.), Children = DataValue(0))]

output_filename2 = tempname() * ".feather"

Expand All @@ -51,17 +51,17 @@ try
@test IteratorInterfaceExtensions.isiterable(featherfile) == true
@test TableTraits.supports_get_columns_copy_using_missing(featherfile) == true
ff_as_cols = TableTraits.get_columns_copy_using_missing(featherfile)
@test isequal(ff_as_cols, (Name=["John", "Sally", missing], Age=[34., missing, 34.], Children=[missing,1,0]))
@test isequal(ff_as_cols, (Name = ["John", "Sally", missing], Age = [34., missing, 34.], Children = [missing,1,0]))
finally
GC.gc()
GC.gc()
# rm(output_filename2)
end
end

ar = load(output_filename2)

@test sprint((stream,data)->show(stream, "text/html", data), ar) == "<table><thead><tr><th>Name</th><th>Age</th><th>Children</th></tr></thead><tbody><tr><td>&quot;John&quot;</td><td>34.0</td><td>#NA</td></tr><tr><td>&quot;Sally&quot;</td><td>#NA</td><td>1</td></tr><tr><td>#NA</td><td>34.0</td><td>0</td></tr></tbody></table>"
@test sprint((stream,data)->show(stream, "application/vnd.dataresource+json", data), ar) == "{\"schema\":{\"fields\":[{\"name\":\"Name\",\"type\":\"string\"},{\"name\":\"Age\",\"type\":\"number\"},{\"name\":\"Children\",\"type\":\"integer\"}]},\"data\":[{\"Name\":\"John\",\"Age\":34.0,\"Children\":null},{\"Name\":\"Sally\",\"Age\":null,\"Children\":1},{\"Name\":null,\"Age\":34.0,\"Children\":0}]}"
@test sprint((stream, data) -> show(stream, "text/html", data), ar) == "<table><thead><tr><th>Name</th><th>Age</th><th>Children</th></tr></thead><tbody><tr><td>&quot;John&quot;</td><td>34.0</td><td>#NA</td></tr><tr><td>&quot;Sally&quot;</td><td>#NA</td><td>1</td></tr><tr><td>#NA</td><td>34.0</td><td>0</td></tr></tbody></table>"
@test sprint((stream, data) -> show(stream, "application/vnd.dataresource+json", data), ar) == "{\"schema\":{\"fields\":[{\"name\":\"Name\",\"type\":\"string\"},{\"name\":\"Age\",\"type\":\"number\"},{\"name\":\"Children\",\"type\":\"integer\"}]},\"data\":[{\"Name\":\"John\",\"Age\":34.0,\"Children\":null},{\"Name\":\"Sally\",\"Age\":null,\"Children\":1},{\"Name\":null,\"Age\":34.0,\"Children\":0}]}"
@test sprint(show, ar) == "3x3 Feather file\nName │ Age │ Children\n────────┼──────┼─────────\n\"John\" │ 34.0 │ #NA \n\"Sally\" │ #NA │ 1 \n#NA │ 34.0 │ 0 "
@test showable("text/html", ar) == true
@test showable("application/vnd.dataresource+json", ar) == true
Expand Down Expand Up @@ -93,7 +93,7 @@ v2 = FeatherFiles.DataValueArrowVector(DictEncoding(["fire", "walk", "with", mis

v3 = FeatherFiles.MissingDataValueVector([DataValue{Int64}(), DataValue{Int64}(18), DataValue{Int64}(54)])
@test getindex(v3, 2) == 18
@test getindex(v3, 1) === missing
@test getindex(v3, 1) === missing
@test IndexStyle(v3) == IndexLinear()

end