Skip to content

Commit

Permalink
iterators fix
Browse files Browse the repository at this point in the history
  • Loading branch information
PharmCat committed Jun 7, 2022
1 parent f380f86 commit c61b928
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ function Base.iterate(itr::SkipNaNorMissing, state...)
end
Base.IndexStyle(::Type{<:SkipNaNorMissing{T}}) where {T} = IndexStyle(T)
Base.eachindex(itr::SkipNaNorMissing) =
Iterators.filter(i -> isnanormissing(@inbounds(itr.x[i])), eachindex(itr.x))
Iterators.filter(i -> !isnanormissing(@inbounds(itr.x[i])), eachindex(itr.x))
Base.keys(itr::SkipNaNorMissing) =
Iterators.filter(i -> isnanormissing(@inbounds(itr.x[i])), keys(itr.x))
Iterators.filter(i -> !isnanormissing(@inbounds(itr.x[i])), keys(itr.x))
Base.@propagate_inbounds function getindex(itr::SkipNaNorMissing, I...)
v = itr.x[I...]
!isnanormissing(v) && throw(ErrorException("The value at index $I is NaN or missing!"))
isnanormissing(v) && throw(ErrorException("The value at index $I is NaN or missing!"))
v
end
function Base.length(itr::SkipNaNorMissing)
Expand Down
29 changes: 29 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Заполняет словарь d индексами индивидуальных значений
#=
function indsdict!(d::Dict{T, Vector{Int}}, cdata) where T
@inbounds for (i, element) in enumerate(zip(cdata...))
ind = ht_keyindex(d, element)
Expand All @@ -12,6 +13,34 @@ function indsdict!(d::Dict{T, Vector{Int}}, cdata) where T
end
d
end
=#
function indsdict!(d::Dict, cdata)
@inbounds for (i, element) in enumerate(zip(cdata...))
ind = ht_keyindex(d, element)
if ind > 0
push!(d.vals[ind], i)
else
v = Vector{Int}(undef, 1)
v[1] = i
d[element] = v
end
end
d
end
function indsdict!(d::Dict, cdata::AbstractVector)
@inbounds for i = 1:length(cdata)
ind = ht_keyindex(d, cdata[i])
if ind > 0
push!(d.vals[ind], i)
else
v = Vector{Int}(undef, 1)
v[1] = i
d[cdata[i]] = v
end
end
d
end

function indsdict!(d::Dict, mt::MetidaTable)
indsdict!(d, table(mt))
end
Expand Down
8 changes: 4 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,18 @@ using Test, Tables, TypedTables, CSV
for i in itr1
@test !MetidaBase.isnanormissing(i)
end
eachindex(itr1)
@test collect(eachindex(itr1)) == [1,2,3]
eltype(itr1)
keys(itr1)
@test collect(keys(itr1)) == [1,2,3]
@test length(itr1) == 3

itr2 = MetidaBase.skipnonpositive(v1)
for i in itr2
@test MetidaBase.ispositive(i)
end
eachindex(itr2)
@test collect(eachindex(itr2)) == [1,2]
eltype(itr2)
keys(itr2)
@test collect(keys(itr2)) == [1,2]
@test length(itr2) == 2

@test MetidaBase.nonunique([1,2,3,3,4,5,6,6]) == [6,3]
Expand Down

2 comments on commit c61b928

@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/61975

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.3 -m "<description of version>" c61b9282253fd78dc592dfe37962c20b7f2a5154
git push origin v0.5.3

Please sign in to comment.