Skip to content

Commit

Permalink
Merge pull request #13 from PharmCat/dev
Browse files Browse the repository at this point in the history
find methods, docs
  • Loading branch information
PharmCat authored Jan 13, 2025
2 parents 3cdfafa + 3f4a98b commit 2de7726
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 19 deletions.
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 @@ 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
Expand All @@ -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)
Expand Down Expand Up @@ -106,15 +108,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
################################################################################
Expand All @@ -123,6 +140,83 @@ 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

################################################################################
# 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 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 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 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 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
################################################################################
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

4 comments on commit 2de7726

@PharmCat
Copy link
Owner Author

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/123080

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

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.13.0 -m "<description of version>" 2de772656f1200adb302361fe1079cb0cd5ed984
git push origin v0.13.0

@PharmCat
Copy link
Owner Author

Choose a reason for hiding this comment

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

@JuliaRegistrator register

Release notes:

Breaking Changes

  • Changed getindex
  • Changed filter
  • Add findlast , findnext , findprev , findallel
  • Add find*el

@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 updated: JuliaRegistries/General/123080

Tagging

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.13.0 -m "<description of version>" 2de772656f1200adb302361fe1079cb0cd5ed984
git push origin v0.13.0

Please sign in to comment.