Skip to content

Commit

Permalink
v0.5.1-p1
Browse files Browse the repository at this point in the history
  • Loading branch information
PharmCat committed Nov 12, 2021
1 parent 5e58194 commit b343e2e
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 17 deletions.
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
name = "MetidaBase"
uuid = "075456b7-4006-432f-9324-2f8453996c49"
authors = ["PharmCat <[email protected]> and contributors"]
version = "0.5.0"
version = "0.5.1"

[deps]
#StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
StatsModels = "3eaba693-59b7-5ba5-a881-562e759f1c8d"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
TypedTables = "9d95f2ec-7b3d-5a63-8d20-e2491e220bb9"
CPUSummary = "2a0fbf3d-bb9c-48f3-b0a9-814d99fd7ab9"

[compat]
#StatsBase = "0.29, 0.30, 0.31, 0.32, 0.33"
StatsBase = "0.29, 0.30, 0.31, 0.32, 0.33"
StatsModels = "0.6"
Tables = "1"
PrettyTables = "1"
Expand Down
2 changes: 1 addition & 1 deletion src/MetidaBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
__precompile__(true)
module MetidaBase

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

#@reexport using StatsModels

Expand Down
36 changes: 24 additions & 12 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,18 @@ function Base.getindex(d::DataSet{T}, col::Colon, ind) where T <: AbstractResult
getresultindex_unsafe.(d.ds, ind)
end

Base.first(d::DataSet) = first(d.ds)
Base.first(d::DataSet) = first(getdata(d))

function Base.length(d::DataSet)
length(d.ds)
length(getdata(d))
end

function Base.iterate(d::DataSet)
return Base.iterate(d.ds)
return Base.iterate(getdata(d))
end

function Base.iterate(d::DataSet, i::Int)
return Base.iterate(d.ds, i)
return Base.iterate(getdata(d), i)
end

function Base.map(f, d::DataSet)
Expand Down Expand Up @@ -208,6 +208,18 @@ function Base.sort!(d::DataSet{T}, k; alg::Base.Algorithm = QuickSort, lt=nothin
d
end

################################################################################
# filter
################################################################################
function Base.filter(f::Function, d::DataSet)
ds = getdata(d)
inds = findall(f, ds)
DataSet(ds[inds])
end
function Base.filter!(f::Function, d::DataSet)
filter!(f, getdata(d))
d
end
################################################################################
# SELF
################################################################################
Expand Down Expand Up @@ -248,8 +260,8 @@ end
function uniqueidlist(d::DataSet{T}, list::AbstractVector{Symbol}) where T <: AbstractIdData
dl = Vector{Dict}(undef, 0)
for i in d
if list keys(i.id)
subd = Dict(k => i.id[k] for k in list)
if list keys(getid(i))
subd = Dict(k => getid(i)[k] for k in list)
if subd dl push!(dl, subd) end
end
end
Expand All @@ -259,22 +271,22 @@ end
function uniqueidlist(d::DataSet{T}, list::Symbol) where T <: AbstractIdData
dl = Vector{Dict}(undef, 0)
for i in d
if list in keys(i.id)
subd = Dict(list => i.id[list])
if list in keys(getid(i))
subd = Dict(list => getid(i)[list])
if subd dl push!(dl, subd) end
end
end
dl
end

function subset(d::DataSet{T}, sort::Dict) where T <: AbstractIdData
inds = findall(x-> sort x.id, d.ds)
if length(inds) > 0 return DataSet(d.ds[inds]) end
inds = findall(x-> sort getid(x), getdata(d))
if length(inds) > 0 return DataSet(getdata(d)[inds]) end
DataSet(Vector{T}(undef, 0))
end
function subset(d::DataSet{T}, sort::Dict) where T <: AbstractIDResult
inds = findall(x-> sort x.data.id, d.ds)
if length(inds) > 0 return DataSet(d.ds[inds]) end
inds = findall(x-> sort getid(x), getdata(d))
if length(inds) > 0 return DataSet(getdata(d)[inds]) end
DataSet(Vector{T}(undef, 0))
end
function subset(d::DataSet{T}, inds) where T
Expand Down
2 changes: 1 addition & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

# Заполняет словарь d индексами индивидуальных значений
function indsdict!(d::Dict{T}, cdata::Tuple) where T
@inbounds for (i, element) in enumerate(zip(cdata...))
ind = ht_keyindex(d, element)
Expand Down
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ using Test, Tables, TypedTables, CSV

@test_nowarn sort!(exrsds, :a)



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

MetidaBase.uniqueidlist(exidds, [:a])
Expand All @@ -106,6 +108,12 @@ using Test, Tables, TypedTables, CSV

@test_nowarn map(identity, exidds)

filtexrsds = filter(x -> x.id[:a] == 2, exidds)
filter!(x -> x.id[:a] == 2, exidds)

@test length(filtexrsds) == length(exidds)
@test filtexrsds[1].id[:a] == exidds[1].id[:a] == 2

mt = MetidaBase.metida_table(exrsds)
mt = MetidaBase.metida_table(exrsds; results = :r1, ids = :a)
smt = MetidaBase.Tables.schema(mt)
Expand Down

2 comments on commit b343e2e

@PharmCat
Copy link
Owner

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

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.5.1 -m "<description of version>" b343e2e49968806184c8e3ab03ef22440044ea79
git push origin v0.5.1

Please sign in to comment.