Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix df export #12

Merged
merged 3 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
: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 @@ -229,7 +141,7 @@
end
if length(vars) == 0 error("No column found for descriptive statistics!") end
end
if eltype(vars) <: Integer vars = Tables.columnnames(data)[vars] end

Check warning on line 144 in src/descriptive.jl

View check run for this annotation

Codecov / codecov/patch

src/descriptive.jl#L144

Added line #L144 was not covered by tests
descriptives(data, vars, sort; kwargs...)
end
"""
Expand All @@ -256,7 +168,7 @@
end
if :qts in k
# Check quantiles
end

Check warning on line 171 in src/descriptive.jl

View check run for this annotation

Codecov / codecov/patch

src/descriptive.jl#L171

Added line #L171 was not covered by tests


if !(:stats in k)
Expand All @@ -271,7 +183,7 @@
if any(x -> x in [:geom, :geomean, :logmean, :logvar, :geocv], kwargs[:stats])
makelogvec = true
else
makelogvec = false

Check warning on line 186 in src/descriptive.jl

View check run for this annotation

Codecov / codecov/patch

src/descriptive.jl#L186

Added line #L186 was not covered by tests
end

if any(x -> x in [:lci, :uci, :lmeanci, :umeanci], kwargs[:stats])
Expand Down Expand Up @@ -477,7 +389,7 @@
#
################################################################################

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 All @@ -499,7 +411,7 @@
if isnothing(sort)
ressetl = collect(resset)
else
ressetl = sortbyvec!(collect(resset), sort)

Check warning on line 414 in src/descriptive.jl

View check run for this annotation

Codecov / codecov/patch

src/descriptive.jl#L414

Added line #L414 was not covered by tests
end
end
if !isnothing(id)
Expand All @@ -509,7 +421,7 @@
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
Loading