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

get rid of CategoricalArrays #157

Merged
merged 8 commits into from
Nov 11, 2019
10 changes: 6 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name = "StatsModels"
uuid = "3eaba693-59b7-5ba5-a881-562e759f1c8d"
version = "0.6.4"
version = "0.6.7"

[deps]
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
DataAPI = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
ShiftedArrays = "1277b4bf-5013-50f5-be3d-901d8477a67a"
Expand All @@ -12,13 +12,15 @@ StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"

[compat]
StatsBase = "≥0.22.0"
julia = "1"
DataAPI = "1.1"
StatsBase = "≥0.22.0"

[extras]
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["DataFrames", "Statistics", "Test"]
test = ["CategoricalArrays", "DataFrames", "Statistics", "Test"]
2 changes: 1 addition & 1 deletion src/StatsModels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module StatsModels
using Tables
using StatsBase
using ShiftedArrays: lag, lead
using CategoricalArrays
using DataStructures
using DataAPI: levels

using SparseArrays
using LinearAlgebra
Expand Down
10 changes: 1 addition & 9 deletions src/modelframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,9 @@ end
function _nonmissing!(res, col)
# workaround until JuliaLang/julia#21256 is fixed
eltype(col) >: Missing || return

@inbounds for (i, el) in enumerate(col)
res[i] &= !ismissing(el)
end
res .&= .!ismissing.(col)
end

function _nonmissing!(res, col::CategoricalArray{>: Missing})
@inbounds for (i, el) in enumerate(col.refs)
res[i] &= el > 0
end
end

function missing_omit(d::T) where T<:ColumnTable
nonmissings = trues(length(first(d)))
Expand Down
6 changes: 3 additions & 3 deletions src/statsmodel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,19 @@ StatsBase.r2(mm::TableRegressionModel, variant::Symbol) = r2(mm.model, variant)
StatsBase.adjr2(mm::TableRegressionModel, variant::Symbol) = adjr2(mm.model, variant)

function _return_predictions(yp::AbstractVector, nonmissings, len)
out = missings(eltype(yp), len)
out = Vector{Union{eltype(yp),Missing}}(missing, len)
out[nonmissings] = yp
out
end

function _return_predictions(yp::AbstractMatrix, nonmissings, len)
out = missings(eltype(yp), (len, 3))
out = Matrix{Union{eltype(yp),Missing}}(missing, len, 3)
out[nonmissings, :] = yp
DataFrame(prediction = out[:,1], lower = out[:,2], upper = out[:,3])
end

function _return_predictions(yp::NamedTuple, nonmissings, len)
y = missings(eltype(yp[:prediction]), len)
y = Vector{Union{eltype(yp.prediction),Missing}}(missing, len)
l, h = similar(y), similar(y)
out = (prediction = y, lower = l, upper = h)
for key in (:prediction, :lower, :upper)
Expand Down