Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
PharmCat committed Jul 5, 2022
1 parent c61b928 commit 3a612a3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/MetidaBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
__precompile__(true)
module MetidaBase

using Tables, PrettyTables, TypedTables, StatsBase#, Reexport
using Tables, PrettyTables, TypedTables, StatsBase, StatsModels#, Reexport

#@reexport using StatsModels

import StatsModels: StatisticalModel
import Tables: istable, columnaccess, columns, getcolumn, columnnames, schema, rowaccess, rows
import CPUSummary: num_cores

import Base: getindex, length, ht_keyindex, show, pushfirst!, iterate, size
import Base: getindex, length, ht_keyindex, show, pushfirst!, iterate, size, findfirst

include("abstracttype.jl")
include("types.jl")
Expand Down
23 changes: 21 additions & 2 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,16 @@ end
function getdata(d::DataSet)
d.ds
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
missing
end

Tables.istable(::AbstractDataSet) = false

Tables.rowaccess(::AbstractDataSet) = false
################################################################################
# BASE
################################################################################
Expand Down Expand Up @@ -209,8 +214,11 @@ end
function Base.map(f, d::DataSet)
DataSet(map(f, getdata(d)))
end

################################################################################
# BASE.SORT
# BASE
################################################################################
# sort!
################################################################################
function islessdict(a::Dict{A1,A2}, b::Dict{B1,B2}, k::Union{AbstractVector, Set}) where A1 where A2 where B1 where B2
l = length(k)
Expand All @@ -234,6 +242,7 @@ end

################################################################################
# filter
# filter!
################################################################################
function Base.filter(f::Function, d::DataSet)
ds = getdata(d)
Expand All @@ -244,6 +253,15 @@ function Base.filter!(f::Function, d::DataSet)
filter!(f, getdata(d))
d
end

################################################################################
# Base.findfirst
################################################################################

function Base.findfirst(d::DataSet{<: AbstractIdData}, sort::Dict)
findfirst(x-> sort getid(x), getdata(d))
end

################################################################################
# SELF
################################################################################
Expand Down Expand Up @@ -303,6 +321,7 @@ function uniqueidlist(d::DataSet{T}, list::Symbol) where T <: AbstractIdData
dl
end


function subset(d::DataSet{T}, sort::Dict) where T <: AbstractIdData
inds = findall(x-> sort getid(x), getdata(d))
if length(inds) > 0 return DataSet(getdata(d)[inds]) end
Expand All @@ -313,7 +332,7 @@ function subset(d::DataSet{T}, sort::Dict) where T <: AbstractIDResult
if length(inds) > 0 return DataSet(getdata(d)[inds]) end
DataSet(Vector{T}(undef, 0))
end
function subset(d::DataSet{T}, inds) where T
function subset(d::DataSet, inds)
DataSet(getdata(d)[inds])
end
################################################################################
Expand Down
3 changes: 2 additions & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ function indsdict!(d::Dict, cdata)
end
d
end
function indsdict!(d::Dict, cdata::AbstractVector)

function indsdict!(d::Dict, cdata::AbstractVector)
@inbounds for i = 1:length(cdata)
ind = ht_keyindex(d, cdata[i])
if ind > 0
Expand Down

0 comments on commit 3a612a3

Please sign in to comment.