Skip to content

Commit

Permalink
Merge pull request #12 from PharmCat/dev
Browse files Browse the repository at this point in the history
fix df export
  • Loading branch information
PharmCat authored Aug 23, 2023
2 parents dfb82a5 + bc5f87e commit cd2d8fc
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 108 deletions.
33 changes: 20 additions & 13 deletions .github/workflows/Tier1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ on:
- 'README.md'
- '.github/**'
- 'docs/**'
- 'validation/**'
- 'test/validation**'
- 'img/**'
- 'change.log'
- '.gitignore'
pull_request:
Expand All @@ -19,24 +18,32 @@ on:
- 'LICENSE.md'
- 'README.md'
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.8, 1]
julia-arch: [x64]
os: [ubuntu-latest, macOS-latest, windows-latest]
version:
- '1.6'
- '1.8'
- '1'
os:
- ubuntu-latest
- macOS-latest
- windows-latest
arch:
- x64
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.julia-version }}
- uses: julia-actions/julia-buildpkg@master
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: julia-actions/cache@v1
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
- uses: julia-actions/julia-processcoverage@v1
if: ${{ matrix.os == 'ubuntu-latest' && matrix.julia-version == '1.8' && matrix.arch == 'x64' }}
- uses: codecov/codecov-action@v1
if: ${{ matrix.os == 'ubuntu-latest' && matrix.julia-version == '1.8' && matrix.arch == 'x64' }}
- uses: codecov/codecov-action@v3
with:
file: lcov.info
files: lcov.info

2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MetidaStats"
uuid = "75cdad26-409a-4e43-8ad7-d54b4fa665a0"
authors = ["PharmCat <v.s.arnautov@yandex.ru>"]
version = "0.2.0"
version = "0.2.1"

[deps]

Expand Down
1 change: 1 addition & 0 deletions src/MetidaStats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module MetidaStats
Tables,
indsdict!,
metida_table,
metida_table_,
getid,
MetidaTable,
sortbyvec!,
Expand Down
92 changes: 2 additions & 90 deletions src/descriptive.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,94 +29,6 @@ const STATLIST = [:n,
:sek,
:sum]

#=
function sortbyvec!(a, vec)
sort!(a, by = x -> findfirst(y -> x == y, vec))
end
=#
#=
ispositive(::Missing) = false
ispositive(x::AbstractFloat) = isnan(x) ? false : x > zero(x)
ispositive(x) = x > zero(x)
################################################################################
struct SkipNonPositive{T}
x::T
end
skipnonpositive(itr) = SkipNonPositive(itr)
Base.IteratorEltype(::Type{SkipNonPositive{T}}) where {T} = Base.IteratorEltype(T)
#Base.eltype(::Type{SkipNonPositive{T}}) where {T} = nonmissingtype(eltype(T))
function Base.iterate(itr::SkipNonPositive, state...)
y = iterate(itr.x, state...)
y === nothing && return nothing
item, state = y
while !ispositive(item)
y = iterate(itr.x, state)
y === nothing && return nothing
item, state = y
end
item, state
end
Base.IndexStyle(::Type{<:SkipNonPositive{T}}) where {T} = IndexStyle(T)
Base.eachindex(itr::SkipNonPositive) =
Iterators.filter(i -> ispositive(@inbounds(itr.x[i])), eachindex(itr.x))
Base.keys(itr::SkipNonPositive) =
Iterators.filter(i -> ispositive(@inbounds(itr.x[i])), keys(itr.x))
Base.@propagate_inbounds function getindex(itr::SkipNonPositive, I...)
v = itr.x[I...]
!ispositive(v) && throw(ErrorException("the value at index $I is non positive"))
v
end
function Base.length(itr::SkipNonPositive)
n = 0
for i in itr n+=1 end
n
end
################################################################################
struct SkipNaNorMissing{T}
x::T
end
skipnanormissing(itr) = SkipNaNorMissing(itr)
Base.IteratorEltype(::Type{SkipNaNorMissing{T}}) where {T} = Base.IteratorEltype(T)
#Base.eltype(::Type{SkipNaNorMissing{T}}) where {T} = nonmissingtype(eltype(T))
function Base.iterate(itr::SkipNaNorMissing, state...)
y = iterate(itr.x, state...)
y === nothing && return nothing
item, state = y
while isnanormissing(item)
y = iterate(itr.x, state)
y === nothing && return nothing
item, state = y
end
item, 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))
Base.keys(itr::SkipNaNorMissing) =
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!"))
v
end
function Base.length(itr::SkipNaNorMissing)
n = 0
for i in itr n+=1 end
n
end
=#
################################################################################
#=
length2(x) = length(x)
function length2(itr::Base.SkipMissing)
n = 0
for i in itr n+=1 end
n
end
=#
################################################################################
"""
dataimport(data; vars, sort = nothing)
Expand Down Expand Up @@ -477,7 +389,7 @@ end
#
################################################################################

function MetidaBase.metida_table(obj::DataSet{DS}; sort = nothing, stats = nothing, id = nothing) where DS <: Descriptives
function MetidaBase.metida_table_(obj::DataSet{DS}; sort = nothing, stats = nothing, id = nothing) where DS <: Descriptives
idset = Set(keys(first(obj).data.id))
resset = Set(keys(first(obj).result))
if length(obj) > 1
Expand Down Expand Up @@ -509,7 +421,7 @@ function MetidaBase.metida_table(obj::DataSet{DS}; sort = nothing, stats = nothi
end
mt1 = metida_table((getid(obj, :, c) for c in idset)...; names = idset)
mt2 = metida_table((obj[:, c] for c in ressetl)...; names = ressetl)
MetidaTable(merge(mt1.table, mt2.table))
merge(mt1.table, mt2.table)
end

################################################################################
Expand Down
12 changes: 8 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using MetidaStats
using MetidaBase
import MetidaBase: metida_table
using StatsBase
using Test
using DataFrames, CSV
Expand All @@ -15,15 +16,18 @@ io = IOBuffer();

di = MetidaStats.dataimport(ds, vars = [:var1, :var2])

mt = MetidaStats.metida_table(des; stats = [:mean, :geom])
mt = metida_table(des; stats = [:mean, :geom])

mt = MetidaStats.metida_table(des; stats = [:mean, :geom], id = [:Variable,:row])
mt = MetidaBase.metida_table(des; stats = [:mean, :geom], id = [:Variable,:row])

des2 = MetidaStats.descriptives(ds, [:var1, :var2], [:col, :row]; skipmissing = true, skipnonpositive = true, stats = MetidaStats.STATLIST)

@test_nowarn DataFrame(des2)

@test des[:, :mean] == des2[:, :mean]

show(io, des)
@test_nowarn show(io, des)
@test_nowarn show(io, di)

sort!(des2, [:col, :row, :Variable])

Expand Down Expand Up @@ -111,7 +115,6 @@ io = IOBuffer();
di = MetidaStats.dataimport(ds, vars = [:var1, :var2], sort = [:col, :row])
sort!(di, [:col, :row, :Variable])


des2[1, :skew] skewness(di[1].obs)

des2[1, :kurt] kurtosis(di[1].obs)
Expand All @@ -121,6 +124,7 @@ io = IOBuffer();
sort!(des3, [:col, :row, :Variable])
@test des3[2, :mean] des2[2, :mean]
@test des3[2, :geom] === NaN

des4 = MetidaStats.descriptives(ds, [:var1], [:col, :row]; skipmissing = false, skipnonpositive = false, stats = MetidaStats.STATLIST)
sort!(des4, [:col, :row, :Variable])
@test des4[1, :mean] des2[1, :mean]
Expand Down

2 comments on commit cd2d8fc

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

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

Please sign in to comment.