Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find methods, docs #13

Merged
merged 4 commits into from
Jan 13, 2025
Merged
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
47 changes: 36 additions & 11 deletions .github/workflows/Tier1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MetidaBase"
uuid = "075456b7-4006-432f-9324-2f8453996c49"
authors = ["PharmCat <[email protected]> and contributors"]
version = "0.12.0"
version = "0.13.0"

[deps]
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
Expand Down
4 changes: 3 additions & 1 deletion src/MetidaBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
102 changes: 98 additions & 4 deletions src/dataset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
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
Expand All @@ -34,6 +34,8 @@
@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))

Check warning on line 38 in src/dataset.jl

View check run for this annotation

Codecov / codecov/patch

src/dataset.jl#L37-L38

Added lines #L37 - L38 were not covered by tests

function Base.getindex(d::DataSet{T}, col::Int, ind) where T <: AbstractResultData
getresultindex_safe(d[col], ind)
Expand Down Expand Up @@ -106,15 +108,30 @@
# 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

Check warning on line 124 in src/dataset.jl

View check run for this annotation

Codecov / codecov/patch

src/dataset.jl#L118-L124

Added lines #L118 - L124 were not covered by tests
end
DataSet(a)

Check warning on line 126 in src/dataset.jl

View check run for this annotation

Codecov / codecov/patch

src/dataset.jl#L126

Added line #L126 was not covered by tests
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

Check warning on line 132 in src/dataset.jl

View check run for this annotation

Codecov / codecov/patch

src/dataset.jl#L128-L132

Added lines #L128 - L132 were not covered by tests
end

################################################################################
# Base.findfirst
################################################################################
Expand All @@ -123,6 +140,83 @@
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

################################################################################
# find*el
################################################################################

function findfirstel(d::DataSet{<: AbstractIdData}, sort::Dict)
ind = findfirst(x-> sort ⊆ getid(x), getdata(d))
if isnothing(ind)
return nothing

Check warning on line 183 in src/dataset.jl

View check run for this annotation

Codecov / codecov/patch

src/dataset.jl#L180-L183

Added lines #L180 - L183 were not covered by tests
else
return d[ind]

Check warning on line 185 in src/dataset.jl

View check run for this annotation

Codecov / codecov/patch

src/dataset.jl#L185

Added line #L185 was not covered by tests
end
end
function findlastel(d::DataSet{<: AbstractIdData}, sort::Dict)
ind = findlast(x-> sort ⊆ getid(x), getdata(d))
if isnothing(ind)
return nothing

Check warning on line 191 in src/dataset.jl

View check run for this annotation

Codecov / codecov/patch

src/dataset.jl#L188-L191

Added lines #L188 - L191 were not covered by tests
else
return d[ind]

Check warning on line 193 in src/dataset.jl

View check run for this annotation

Codecov / codecov/patch

src/dataset.jl#L193

Added line #L193 was not covered by tests
end
end
function findnextel(d::DataSet{<: AbstractIdData}, sort::Dict, i::Int)
ind = findnext(x-> sort ⊆ getid(x), getdata(d), i)
if isnothing(ind)
return nothing

Check warning on line 199 in src/dataset.jl

View check run for this annotation

Codecov / codecov/patch

src/dataset.jl#L196-L199

Added lines #L196 - L199 were not covered by tests
else
return d[ind]

Check warning on line 201 in src/dataset.jl

View check run for this annotation

Codecov / codecov/patch

src/dataset.jl#L201

Added line #L201 was not covered by tests
end
end
function findprevel(d::DataSet{<: AbstractIdData}, sort::Dict, i::Int)
ind = findprev(x-> sort ⊆ getid(x), getdata(d), i)
if isnothing(ind)
return nothing

Check warning on line 207 in src/dataset.jl

View check run for this annotation

Codecov / codecov/patch

src/dataset.jl#L204-L207

Added lines #L204 - L207 were not covered by tests
else
return d[ind]

Check warning on line 209 in src/dataset.jl

View check run for this annotation

Codecov / codecov/patch

src/dataset.jl#L209

Added line #L209 was not covered by tests
end
end
function findallel(d::DataSet{<: AbstractIdData}, sort::Dict)
ind = findall(x-> sort ⊆ getid(x), getdata(d))
if isnothing(ind)
return nothing

Check warning on line 215 in src/dataset.jl

View check run for this annotation

Codecov / codecov/patch

src/dataset.jl#L212-L215

Added lines #L212 - L215 were not covered by tests
else
return d[ind]

Check warning on line 217 in src/dataset.jl

View check run for this annotation

Codecov / codecov/patch

src/dataset.jl#L217

Added line #L217 was not covered by tests
end
end
################################################################################
# SELF
################################################################################
Expand Down
2 changes: 1 addition & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ end
"""
cvfromsd(σ::Real)::AbstractFloat
CV from variance.
CV from LnSD.
"""
function cvfromsd(σ)
return sqrt(exp^2) - 1)
Expand Down
5 changes: 4 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
#######################################################################


Expand Down
Loading