Skip to content

Commit

Permalink
better handling of missing in wrapped type
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierlabayle committed Mar 29, 2024
1 parent 1869dbb commit fa165e0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ end

wrapped_type(x) = x
wrapped_type(x::Type{<:CategoricalValue{T,}}) where T = T

wrapped_type(x::Type{Union{Missing, T}}) where T = wrapped_type(T)
"""
Uses the values found in the dataset to create a new estimand with adjusted values.
"""
Expand Down Expand Up @@ -137,7 +137,7 @@ end

function make_categorical!(dataset, colnames; infer_ordered=false)
for colname in colnames
make_categorical!(dataset, colname;infer_ordered=infer_ordered)
make_categorical!(dataset, colname; infer_ordered=infer_ordered)
end
end

Expand Down
10 changes: 10 additions & 0 deletions test/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,16 @@ end
data.W₁ = [1, 2, missing, 4, 5]
sample_ids = TargetedEstimation.sample_ids_from_variables(data, variables)
@test sample_ids == [2]
# wrapped_ype
col = categorical(["AC", "CC"])
@test TargetedEstimation.wrapped_type(eltype(col)) == String
col = categorical(["AC", "CC", missing])
@test TargetedEstimation.wrapped_type(eltype(col)) == String
col = [1, missing, 0.3]
@test TargetedEstimation.wrapped_type(eltype(col)) == Float64
col = [1, 2, 3]
@test TargetedEstimation.wrapped_type(eltype(col)) == Int64

end

@testset "Test make_categorical! and make_float!" begin
Expand Down

0 comments on commit fa165e0

Please sign in to comment.