From b28176160ed771c7cb306c0b6efef04a0a7a4b1e Mon Sep 17 00:00:00 2001 From: PharmCat <13901158+PharmCat@users.noreply.github.com> Date: Wed, 8 Jan 2025 20:52:24 +0300 Subject: [PATCH 1/4] find methods, docs --- Project.toml | 2 +- src/MetidaBase.jl | 4 +++- src/dataset.jl | 56 ++++++++++++++++++++++++++++++++++++++++++++--- src/utils.jl | 2 +- test/runtests.jl | 5 ++++- 5 files changed, 62 insertions(+), 7 deletions(-) diff --git a/Project.toml b/Project.toml index 93b9adb..e96bb27 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "MetidaBase" uuid = "075456b7-4006-432f-9324-2f8453996c49" authors = ["PharmCat and contributors"] -version = "0.12.0" +version = "0.12.1" [deps] CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597" diff --git a/src/MetidaBase.jl b/src/MetidaBase.jl index 3f39574..650f213 100644 --- a/src/MetidaBase.jl +++ b/src/MetidaBase.jl @@ -9,7 +9,9 @@ module MetidaBase import Tables: istable, columnaccess, columns, getcolumn, columnnames, schema, rowaccess, rows import CPUSummary: num_cores - import Base: getindex, length, ht_keyindex, show, pushfirst!, iterate, size, findfirst, push!, append! + import Base: getindex, length, ht_keyindex, show, pushfirst!, iterate, size, findfirst, findlast, findall, findnext, findprev, push!, append! + + export DataSet, MetidaTable, getdata, getid include("abstracttype.jl") include("m_tables.jl") diff --git a/src/dataset.jl b/src/dataset.jl index a7040c6..f942855 100644 --- a/src/dataset.jl +++ b/src/dataset.jl @@ -106,15 +106,30 @@ end # filter! ################################################################################ function Base.filter(f::Function, d::DataSet) - ds = getdata(d) - inds = findall(f, ds) - DataSet(ds[inds]) + DataSet(filter(f, getdata(d))) end function Base.filter!(f::Function, d::DataSet) filter!(f, getdata(d)) d end +function Base.filter(f::Dict{:Symbol, Function}, d::DataSet) + k = keys(f) + a = filter(x -> f[first(k)](getid(x, first(k))), getdata(d)) + if length(k) > 1 + for kn = 2:length(k) + filter!(x -> f[k[kn]](getid(x, k[kn])), a) + end + end + DataSet(a) +end +function Base.filter!(f::Dict{:Symbol, Function}, d::DataSet) + for k in keys(f) + filter!(x -> f[k](getid(x, k)), getdata(d)) + end + d +end + ################################################################################ # Base.findfirst ################################################################################ @@ -123,6 +138,41 @@ function Base.findfirst(d::DataSet{<: AbstractIdData}, sort::Dict) findfirst(x-> sort ⊆ getid(x), getdata(d)) end +################################################################################ +# Base.findlast +################################################################################ + +function Base.findlast(d::DataSet{<: AbstractIdData}, sort::Dict) + findlast(x-> sort ⊆ getid(x), getdata(d)) +end + +################################################################################ +# Base.findnext +################################################################################ + +function Base.findnext(d::DataSet{<: AbstractIdData}, sort::Dict, i::Int) + findnext(x-> sort ⊆ getid(x), getdata(d), i) +end + + +################################################################################ +# Base.findprev +################################################################################ + +function Base.findprev(d::DataSet{<: AbstractIdData}, sort::Dict, i::Int) + findprev(x-> sort ⊆ getid(x), getdata(d), i) +end + +################################################################################ +# Base.findall +################################################################################ + +function Base.findall(d::DataSet{<: AbstractIdData}, sort::Dict) + findall(x-> sort ⊆ getid(x), getdata(d)) +end + + + ################################################################################ # SELF ################################################################################ diff --git a/src/utils.jl b/src/utils.jl index 343f5e8..815257c 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -101,7 +101,7 @@ end """ cvfromsd(σ::Real)::AbstractFloat -CV from variance. +CV from LnSD. """ function cvfromsd(σ) return sqrt(exp(σ^2) - 1) diff --git a/test/runtests.jl b/test/runtests.jl index 51cab84..904eb62 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -149,7 +149,10 @@ using Test, Tables, TypedTables, DataFrames, CSV ######################################################################## @test MetidaBase.findfirst(exidds, Dict(:a => 1, :b => 1)) == 1 - + @test MetidaBase.findlast(exidds, Dict(:a => 1, :b => 1)) == 1 + @test MetidaBase.findall(exidds, Dict(:a => 1, :b => 1)) == [1] + @test MetidaBase.findnext(exidds, Dict(:a => 2, :b => 3), 1) ==2 + @test MetidaBase.findprev(exidds, Dict(:a => 2, :b => 3), 3) == 2 ####################################################################### From 250c32037f3fa8339dcbf1f26045849de4122768 Mon Sep 17 00:00:00 2001 From: PharmCat <13901158+PharmCat@users.noreply.github.com> Date: Wed, 8 Jan 2025 20:56:59 +0300 Subject: [PATCH 2/4] update --- .github/workflows/Tier1.yml | 47 ++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/.github/workflows/Tier1.yml b/.github/workflows/Tier1.yml index e099883..f9d227f 100644 --- a/.github/workflows/Tier1.yml +++ b/.github/workflows/Tier1.yml @@ -16,22 +16,47 @@ on: paths-ignore: - 'LICENSE.md' - 'README.md' +concurrency: + # Skip intermediate builds: always. + # Cancel intermediate builds: only if it is a pull request build. + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }} 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.7, 1.8] - julia-arch: [x64] - os: [ubuntu-latest, macOS-latest, windows-2019] + version: + - '1.8' + - '1' + os: + - ubuntu-latest + - macOS-latest + - windows-latest + arch: + - x64 steps: - - uses: actions/checkout@v3 - - uses: julia-actions/setup-julia@v1 + - uses: actions/checkout@v4 + - uses: julia-actions/setup-julia@v2 with: - version: ${{ matrix.julia-version }} + version: ${{ matrix.version }} + arch: ${{ matrix.arch }} + - uses: actions/cache@v4 + env: + cache-name: cache-artifacts + with: + path: ~/.julia/artifacts + key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }} + restore-keys: | + ${{ runner.os }}-test-${{ env.cache-name }}- + ${{ runner.os }}-test- + ${{ runner.os }}- - uses: julia-actions/julia-buildpkg@v1 - uses: julia-actions/julia-runtest@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - uses: julia-actions/julia-uploadcodecov@latest - if: ${{ startsWith(matrix.os, 'Ubuntu') && startsWith(matrix.julia-version, '1.6') }} + - uses: julia-actions/julia-processcoverage@v1 + - uses: codecov/codecov-action@v4 + if: ${{ matrix.os == 'ubuntu-latest' && matrix.version == '1' && matrix.arch == 'x64' }} + with: + file: lcov.info + token: ${{ secrets.CODECOV_TOKEN }} From 7cd035003b988014387df443641d66a75fea3641 Mon Sep 17 00:00:00 2001 From: PharmCat <13901158+PharmCat@users.noreply.github.com> Date: Mon, 13 Jan 2025 22:33:29 +0300 Subject: [PATCH 3/4] get ind, find els --- Project.toml | 2 +- src/dataset.jl | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/Project.toml b/Project.toml index e96bb27..d9a0204 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "MetidaBase" uuid = "075456b7-4006-432f-9324-2f8453996c49" authors = ["PharmCat and contributors"] -version = "0.12.1" +version = "0.13.0" [deps] CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597" diff --git a/src/dataset.jl b/src/dataset.jl index f942855..817fdc0 100644 --- a/src/dataset.jl +++ b/src/dataset.jl @@ -25,7 +25,7 @@ function Base.getindex(d::DataSet, ind::Int) d.ds[ind] end -Base.getindex(d::DataSet, inds::UnitRange{Int64}) = subset(d, inds) +Base.getindex(d::DataSet, inds) = subset(d, inds) @inline function getresultindex_safe(rd::T, ind::Symbol) where T <: AbstractResultData @@ -34,6 +34,8 @@ end @inline function getresultindex_unsafe(rd::T, ind::Symbol) where T <: AbstractResultData rd.result[ind] end +getresultindex_safe(rd, ind::AbstractString) = getresultindex_safe(rd, Symbol(ind)) +getresultindex_unsafe(rd, ind::AbstractString) = getresultindex_unsafe(rd, Symbol(ind)) function Base.getindex(d::DataSet{T}, col::Int, ind) where T <: AbstractResultData getresultindex_safe(d[col], ind) @@ -171,8 +173,50 @@ function Base.findall(d::DataSet{<: AbstractIdData}, sort::Dict) findall(x-> sort ⊆ getid(x), getdata(d)) end +################################################################################ +# find*el +################################################################################ - +function findfirstel(d::DataSet{<: AbstractIdData}, sort::Dict) + ind = findfirst(x-> sort ⊆ getid(x), getdata(d)) + if isnothing(ind) + return nothing + else + return d[ind] + end +end +function Base.findlastel(d::DataSet{<: AbstractIdData}, sort::Dict) + ind = findlast(x-> sort ⊆ getid(x), getdata(d)) + if isnothing(ind) + return nothing + else + return d[ind] + end +end +function Base.findnextel(d::DataSet{<: AbstractIdData}, sort::Dict, i::Int) + ind = findnext(x-> sort ⊆ getid(x), getdata(d), i) + if isnothing(ind) + return nothing + else + return d[ind] + end +end +function Base.findprevel(d::DataSet{<: AbstractIdData}, sort::Dict, i::Int) + ind = findprev(x-> sort ⊆ getid(x), getdata(d), i) + if isnothing(ind) + return nothing + else + return d[ind] + end +end +function Base.findallel(d::DataSet{<: AbstractIdData}, sort::Dict) + ind = findall(x-> sort ⊆ getid(x), getdata(d)) + if isnothing(ind) + return nothing + else + return d[ind] + end +end ################################################################################ # SELF ################################################################################ From 3f4a98bb0582bed658e3fec2db64522c223da09e Mon Sep 17 00:00:00 2001 From: PharmCat <13901158+PharmCat@users.noreply.github.com> Date: Mon, 13 Jan 2025 22:51:03 +0300 Subject: [PATCH 4/4] fix --- src/dataset.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/dataset.jl b/src/dataset.jl index 817fdc0..1466e2c 100644 --- a/src/dataset.jl +++ b/src/dataset.jl @@ -185,7 +185,7 @@ function findfirstel(d::DataSet{<: AbstractIdData}, sort::Dict) return d[ind] end end -function Base.findlastel(d::DataSet{<: AbstractIdData}, sort::Dict) +function findlastel(d::DataSet{<: AbstractIdData}, sort::Dict) ind = findlast(x-> sort ⊆ getid(x), getdata(d)) if isnothing(ind) return nothing @@ -193,7 +193,7 @@ function Base.findlastel(d::DataSet{<: AbstractIdData}, sort::Dict) return d[ind] end end -function Base.findnextel(d::DataSet{<: AbstractIdData}, sort::Dict, i::Int) +function findnextel(d::DataSet{<: AbstractIdData}, sort::Dict, i::Int) ind = findnext(x-> sort ⊆ getid(x), getdata(d), i) if isnothing(ind) return nothing @@ -201,7 +201,7 @@ function Base.findnextel(d::DataSet{<: AbstractIdData}, sort::Dict, i::Int) return d[ind] end end -function Base.findprevel(d::DataSet{<: AbstractIdData}, sort::Dict, i::Int) +function findprevel(d::DataSet{<: AbstractIdData}, sort::Dict, i::Int) ind = findprev(x-> sort ⊆ getid(x), getdata(d), i) if isnothing(ind) return nothing @@ -209,7 +209,7 @@ function Base.findprevel(d::DataSet{<: AbstractIdData}, sort::Dict, i::Int) return d[ind] end end -function Base.findallel(d::DataSet{<: AbstractIdData}, sort::Dict) +function findallel(d::DataSet{<: AbstractIdData}, sort::Dict) ind = findall(x-> sort ⊆ getid(x), getdata(d)) if isnothing(ind) return nothing