diff --git a/.github/workflows/Tier1.yml b/.github/workflows/Tier1.yml index 8eb8b21..bf90f0c 100644 --- a/.github/workflows/Tier1.yml +++ b/.github/workflows/Tier1.yml @@ -8,8 +8,7 @@ on: - 'README.md' - '.github/**' - 'docs/**' - - 'validation/**' - - 'test/validation**' + - 'img/**' - 'change.log' - '.gitignore' pull_request: @@ -19,24 +18,32 @@ on: - 'LICENSE.md' - 'README.md' jobs: - ci: + test: + name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} runs-on: ${{ matrix.os }} strategy: matrix: - julia-version: [1.6, 1.8, 1] - julia-arch: [x64] - os: [ubuntu-latest, macOS-latest, windows-latest] + version: + - '1.6' + - '1.8' + - '1' + os: + - ubuntu-latest + - macOS-latest + - windows-latest + arch: + - x64 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: julia-actions/setup-julia@v1 with: - version: ${{ matrix.julia-version }} - - uses: julia-actions/julia-buildpkg@master + version: ${{ matrix.version }} + arch: ${{ matrix.arch }} + - uses: julia-actions/cache@v1 + - uses: julia-actions/julia-buildpkg@v1 - uses: julia-actions/julia-runtest@v1 - uses: julia-actions/julia-processcoverage@v1 - if: ${{ matrix.os == 'ubuntu-latest' && matrix.julia-version == '1.8' && matrix.arch == 'x64' }} - - uses: codecov/codecov-action@v1 - if: ${{ matrix.os == 'ubuntu-latest' && matrix.julia-version == '1.8' && matrix.arch == 'x64' }} + - uses: codecov/codecov-action@v3 with: - file: lcov.info + files: lcov.info diff --git a/Project.toml b/Project.toml index 473cc91..54ed630 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "MetidaStats" uuid = "75cdad26-409a-4e43-8ad7-d54b4fa665a0" authors = ["PharmCat "] -version = "0.2.0" +version = "0.2.1" [deps] diff --git a/src/MetidaStats.jl b/src/MetidaStats.jl index 5e5f1dd..2eaa893 100644 --- a/src/MetidaStats.jl +++ b/src/MetidaStats.jl @@ -8,6 +8,7 @@ module MetidaStats Tables, indsdict!, metida_table, + metida_table_, getid, MetidaTable, sortbyvec!, diff --git a/src/descriptive.jl b/src/descriptive.jl index 86d0ceb..29f36a1 100644 --- a/src/descriptive.jl +++ b/src/descriptive.jl @@ -29,94 +29,6 @@ const STATLIST = [:n, :sek, :sum] -#= -function sortbyvec!(a, vec) - sort!(a, by = x -> findfirst(y -> x == y, vec)) -end -=# -#= -ispositive(::Missing) = false -ispositive(x::AbstractFloat) = isnan(x) ? false : x > zero(x) -ispositive(x) = x > zero(x) -################################################################################ -struct SkipNonPositive{T} - x::T -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)) -function Base.iterate(itr::SkipNonPositive, state...) - y = iterate(itr.x, state...) - y === nothing && return nothing - item, state = y - while !ispositive(item) - y = iterate(itr.x, state) - y === nothing && return nothing - item, state = y - end - item, state -end -Base.IndexStyle(::Type{<:SkipNonPositive{T}}) where {T} = IndexStyle(T) -Base.eachindex(itr::SkipNonPositive) = - Iterators.filter(i -> ispositive(@inbounds(itr.x[i])), eachindex(itr.x)) -Base.keys(itr::SkipNonPositive) = - Iterators.filter(i -> ispositive(@inbounds(itr.x[i])), keys(itr.x)) -Base.@propagate_inbounds function getindex(itr::SkipNonPositive, I...) - v = itr.x[I...] - !ispositive(v) && throw(ErrorException("the value at index $I is non positive")) - v -end -function Base.length(itr::SkipNonPositive) - n = 0 - for i in itr n+=1 end - n -end -################################################################################ -struct SkipNaNorMissing{T} - x::T -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)) -function Base.iterate(itr::SkipNaNorMissing, state...) - y = iterate(itr.x, state...) - y === nothing && return nothing - item, state = y - while isnanormissing(item) - y = iterate(itr.x, state) - y === nothing && return nothing - item, state = y - end - item, state -end -Base.IndexStyle(::Type{<:SkipNaNorMissing{T}}) where {T} = IndexStyle(T) -Base.eachindex(itr::SkipNaNorMissing) = - Iterators.filter(i -> isnanormissing(@inbounds(itr.x[i])), eachindex(itr.x)) -Base.keys(itr::SkipNaNorMissing) = - Iterators.filter(i -> isnanormissing(@inbounds(itr.x[i])), keys(itr.x)) -Base.@propagate_inbounds function getindex(itr::SkipNaNorMissing, I...) - v = itr.x[I...] - !isnanormissing(v) && throw(ErrorException("The value at index $I is NaN or missing!")) - v -end -function Base.length(itr::SkipNaNorMissing) - n = 0 - for i in itr n+=1 end - n -end -=# -################################################################################ -#= -length2(x) = length(x) -function length2(itr::Base.SkipMissing) - n = 0 - for i in itr n+=1 end - n -end -=# -################################################################################ """ dataimport(data; vars, sort = nothing) @@ -477,7 +389,7 @@ end # ################################################################################ -function MetidaBase.metida_table(obj::DataSet{DS}; sort = nothing, stats = nothing, id = nothing) where DS <: Descriptives +function MetidaBase.metida_table_(obj::DataSet{DS}; sort = nothing, stats = nothing, id = nothing) where DS <: Descriptives idset = Set(keys(first(obj).data.id)) resset = Set(keys(first(obj).result)) if length(obj) > 1 @@ -509,7 +421,7 @@ function MetidaBase.metida_table(obj::DataSet{DS}; sort = nothing, stats = nothi end mt1 = metida_table((getid(obj, :, c) for c in idset)...; names = idset) mt2 = metida_table((obj[:, c] for c in ressetl)...; names = ressetl) - MetidaTable(merge(mt1.table, mt2.table)) + merge(mt1.table, mt2.table) end ################################################################################ diff --git a/test/runtests.jl b/test/runtests.jl index 42ba052..19e7e66 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,6 @@ using MetidaStats using MetidaBase +import MetidaBase: metida_table using StatsBase using Test using DataFrames, CSV @@ -15,15 +16,18 @@ io = IOBuffer(); di = MetidaStats.dataimport(ds, vars = [:var1, :var2]) - mt = MetidaStats.metida_table(des; stats = [:mean, :geom]) + mt = metida_table(des; stats = [:mean, :geom]) - mt = MetidaStats.metida_table(des; stats = [:mean, :geom], id = [:Variable,:row]) + mt = MetidaBase.metida_table(des; stats = [:mean, :geom], id = [:Variable,:row]) des2 = MetidaStats.descriptives(ds, [:var1, :var2], [:col, :row]; skipmissing = true, skipnonpositive = true, stats = MetidaStats.STATLIST) + @test_nowarn DataFrame(des2) + @test des[:, :mean] == des2[:, :mean] - show(io, des) + @test_nowarn show(io, des) + @test_nowarn show(io, di) sort!(des2, [:col, :row, :Variable]) @@ -111,7 +115,6 @@ io = IOBuffer(); di = MetidaStats.dataimport(ds, vars = [:var1, :var2], sort = [:col, :row]) sort!(di, [:col, :row, :Variable]) - des2[1, :skew] ≈ skewness(di[1].obs) des2[1, :kurt] ≈ kurtosis(di[1].obs) @@ -121,6 +124,7 @@ io = IOBuffer(); sort!(des3, [:col, :row, :Variable]) @test des3[2, :mean] ≈ des2[2, :mean] @test des3[2, :geom] === NaN + des4 = MetidaStats.descriptives(ds, [:var1], [:col, :row]; skipmissing = false, skipnonpositive = false, stats = MetidaStats.STATLIST) sort!(des4, [:col, :row, :Variable]) @test des4[1, :mean] ≈ des2[1, :mean]