Skip to content

Commit

Permalink
v 0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
PharmCat committed Aug 16, 2021
1 parent 266367d commit d79bf10
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
7 changes: 3 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
name = "MetidaBase"
uuid = "075456b7-4006-432f-9324-2f8453996c49"
authors = ["PharmCat <[email protected]> and contributors"]
version = "0.3.2"
version = "0.4.0"

[deps]
#StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
StatsModels = "3eaba693-59b7-5ba5-a881-562e759f1c8d"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
#Reexport = "189a3867-3050-52da-a836-e630ba90ab69"

[compat]
#StatsBase = "0.29, 0.30, 0.31, 0.32, 0.33"
StatsModels = "0.6"
Tables = "1"
PrettyTables = "1"
#Reexport = "0.2, 1.0, 1.1"
julia = "1"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"

[targets]
test = ["Test", "DataFrames"]
test = ["Test", "DataFrames", "CSV"]
4 changes: 2 additions & 2 deletions src/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ end
skipnonpositive(itr) = SkipNonPositive(itr)

Base.IteratorEltype(::Type{SkipNonPositive{T}}) where {T} = Base.IteratorEltype(T)
#Base.eltype(::Type{SkipNonPositive{T}}) where {T} = nonmissingtype(eltype(T))
Base.eltype(::Type{SkipNonPositive{T}}) where {T} = nonmissingtype(eltype(T))
function Base.iterate(itr::SkipNonPositive, state...)
y = iterate(itr.x, state...)
y === nothing && return nothing
Expand Down Expand Up @@ -39,7 +39,7 @@ end
skipnanormissing(itr) = SkipNaNorMissing(itr)

Base.IteratorEltype(::Type{SkipNaNorMissing{T}}) where {T} = Base.IteratorEltype(T)
#Base.eltype(::Type{SkipNaNorMissing{T}}) where {T} = nonmissingtype(eltype(T))
Base.eltype(::Type{SkipNaNorMissing{T}}) where {T} = nonmissingtype(eltype(T))
function Base.iterate(itr::SkipNaNorMissing, state...)
y = iterate(itr.x, state...)
y === nothing && return nothing
Expand Down
12 changes: 10 additions & 2 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ function Base.iterate(d::DataSet, i::Int)
return Base.iterate(d.ds, i)
end

function Base.map(f, d::DataSet)
DataSet(map(f, getdata(d)))
end
################################################################################
# BASE.SORT
################################################################################
Expand Down Expand Up @@ -256,10 +259,15 @@ function uniqueidlist(d::DataSet{T}, list::Symbol) where T <: AbstractIdData
dl
end

function subset(d::DataSet, sort::Dict)
function subset(d::DataSet{T}, sort::Dict) where T <: AbstractIdData
inds = findall(x-> sort x.id, d.ds)
if length(inds) > 0 return DataSet(d.ds[inds]) end
[]
DataSet(Vector{T}(undef, 0))
end
function subset(d::DataSet{T}, sort::Dict) where T <: AbstractIDResult
inds = findall(x-> sort x.data.id, d.ds)
if length(inds) > 0 return DataSet(d.ds[inds]) end
DataSet(Vector{T}(undef, 0))
end
################################################################################
# metida_table from DataSet{AbstractIDResult}
Expand Down
18 changes: 17 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using MetidaBase
using Test, DataFrames
using Test, DataFrames, CSV

@testset "MetidaBase.jl" begin
io = IOBuffer();
Expand All @@ -26,6 +26,8 @@ using Test, DataFrames
@test mt[i, :b] == j[2]
end

CSV.write(io, mt)

struct ExampleIDStruct <: MetidaBase.AbstractSubject
#time
#obs
Expand Down Expand Up @@ -60,6 +62,7 @@ using Test, DataFrames

exrsds = MetidaBase.DataSet(exrsdsv)


@test exrsds[:, :r1][1] == 3
@test exrsds[1, :r1] == 3

Expand All @@ -77,6 +80,9 @@ using Test, DataFrames
MetidaBase.uniqueidlist(exidds, :a)

MetidaBase.subset(exidds, Dict(:a => 1))
MetidaBase.subset(exrsds, Dict(:a => 1))

map(identity, exidds)

mt = MetidaBase.metida_table(exrsds)

Expand All @@ -85,15 +91,25 @@ using Test, DataFrames
for i in itr1
@test !MetidaBase.isnanormissing(i)
end
eachindex(itr1)
eltype(itr1)
keys(itr1)
@test length(itr1) == 3

itr2 = MetidaBase.skipnonpositive(v1)
for i in itr2
@test MetidaBase.ispositive(i)
end
eachindex(itr2)
eltype(itr2)
keys(itr2)
@test length(itr2) == 2

MetidaBase.sdfromcv(0.4) 0.38525317015992666
MetidaBase.varfromcv(0.4) 0.1484200051182734
MetidaBase.cvfromvar(0.4) 0.7013021443295824
MetidaBase.cvfromsd(0.4) 0.41654636115540644

smt = MetidaBase.Tables.schema(mt)

end

2 comments on commit d79bf10

@PharmCat
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/42981

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.0 -m "<description of version>" d79bf107cbe29893340da7a61c2859fc854c3d22
git push origin v0.4.0

Please sign in to comment.