Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Heptazhou committed May 25, 2024
1 parent c2a422a commit ab0c503
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Exts"
uuid = "0b12d779-4123-4875-9d6c-e33c2e29e2c9"
authors = ["Heptazhou <zhou at 0h7z dot com>"]
version = "0.1.1"
version = "0.1.2"

[deps]
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
Expand Down
5 changes: 3 additions & 2 deletions ext/DataFramesExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ using DataFrames: DataFrame
using DelimitedFiles: readdlm, writedlm

function Base.read(s::IOStream, ::Type{DataFrame})
t::NTuple{2, Matrix} = readdlm(s, header = true)
t::NTuple{2, Matrix} = readdlm(s, header = true, comments = true)
DataFrame(t[1], vec(t[2]))
end

function Base.write(s::IOStream, x::DataFrame)
pos₀ = position(s)
writedlm(s, [propertynames(x)'; Matrix(x)])
filesize(s)
position(s) - pos₀
end

end # module
Expand Down
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
8 changes: 5 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ end

@testset "DataFramesExt" begin
using DataFrames: DataFrame
df = DataFrame(rand(Int16, (8, 2)), :auto)
df = DataFrame(rand(Int16, (8, 2)), [:x, :y])
tmp = tempname()
@test_nowarn write(tmp, df)
@test read(tmp, DataFrame) == df
using CSV: CSV
@test 36 write(tmp, df) == filesize(tmp)
@test df == read(tmp, DataFrame)
@test df == CSV.read(tmp, DataFrame)
end

@testset "StatisticsExt" begin
Expand Down

0 comments on commit ab0c503

Please sign in to comment.