Skip to content

Commit

Permalink
Merge pull request #7 from PharmCat/dev
Browse files Browse the repository at this point in the history
v0.11.2
  • Loading branch information
PharmCat authored May 8, 2023
2 parents f0f9f6d + ee3876a commit ca6f554
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Tier1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
julia-arch: [x64]
os: [ubuntu-latest, macOS-latest, windows-2019]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.julia-version }}
Expand Down
9 changes: 4 additions & 5 deletions src/dataset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ function getdata(d::DataSet)
end

@inline function getindormiss(d::Dict{K}, i::K) where K
ind::Int = ht_keyindex(d, i)
if ind > 0 return d.vals[ind] end
if haskey(d, i) return d[i] end
missing
end

Expand Down Expand Up @@ -41,7 +40,7 @@ function Base.getindex(d::DataSet{T}, col::Int, ind) where T <: AbstractResultDa
end
function Base.getindex(d::DataSet{T}, col::Colon, ind) where T <: AbstractResultData
@inbounds for i in Base.OneTo(length(d))
if Base.ht_keyindex(d.ds[i].result, ind) < 1 return getresultindex_safe.(d.ds, ind) end
if !haskey(d.ds[i].result, ind) return getresultindex_safe.(d.ds, ind) end
end
getresultindex_unsafe.(d.ds, ind)
end
Expand Down Expand Up @@ -149,13 +148,13 @@ function getid(d::DataSet{T}, col::Int, ind) where T <: Union{AbstractIdData, Ab
end
function getid(d::DataSet{T}, col::Colon, ind) where T <: AbstractIdData
@inbounds for i in Base.OneTo(length(d))
if Base.ht_keyindex(d.ds[i].id, ind) < 1 return getid_safe.(d.ds, ind) end
if !haskey(d.ds[i].id, ind) return getid_safe.(d.ds, ind) end
end
getid_unsafe.(d.ds, ind)
end
function getid(d::DataSet{T}, col::Colon, ind) where T <: AbstractIDResult
@inbounds for i in Base.OneTo(length(d))
if Base.ht_keyindex(d.ds[i].data.id, ind) < 1 return getid_safe.(d.ds, ind) end
if !haskey(d.ds[i].data.id, ind) return getid_safe.(d.ds, ind) end
end
getid_unsafe.(d.ds, ind)
end
Expand Down
24 changes: 24 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ using Test, Tables, TypedTables, DataFrames, CSV
exiddsv[i] = ExampleIDStruct(Dict(:a => 1, :b => 1))
end
exidds = MetidaBase.DataSet(exiddsv)
############################################################################
item = ExampleIDStruct(Dict(:c => 6, :j => 6))
ds1 = deepcopy(exidds)
ds2 = deepcopy(exidds)
append!(ds1, ds2)
@test length(ds1) == 6
@test MetidaBase.getid(ds1[1])[:a] == MetidaBase.getid(ds1[4])[:a]
push!(ds1, item)
@test length(ds1) == 7
@test MetidaBase.getid(ds1[7]) === item.id

############################################################################
# DATASET Tests
# Test length
Expand All @@ -112,7 +123,9 @@ using Test, Tables, TypedTables, DataFrames, CSV
@test exrsds[1, :r1] == 3

@test MetidaBase.getid(exidds[3], :a) == 2
######################################################################
# SORT
######################################################################
sort!(exidds, :a)
@test MetidaBase.getid(exidds[3], :a) == 3
MetidaBase.getid(exrsds, :, :a)
Expand All @@ -121,6 +134,17 @@ using Test, Tables, TypedTables, DataFrames, CSV

@test first(exrsds) == exrsds[1]

@test_nowarn sort!(exrsds, [:a, :b])

########################################################################
# findfirst
########################################################################

@test MetidaBase.findfirst(exidds, Dict(:a => 1, :b => 1)) == 1

#######################################################################


MetidaBase.uniqueidlist(exidds, [:a])
MetidaBase.uniqueidlist(exidds, :a)

Expand Down

0 comments on commit ca6f554

Please sign in to comment.