Skip to content

Commit daa0879

Browse files
authored
Merge pull request #74 from JuliaAI/dev
For a 0.1.15 release
2 parents 79ee322 + 8011efb commit daa0879

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "CategoricalDistributions"
22
uuid = "af321ab8-2d2e-40a6-b165-3d674595d28e"
33
authors = ["Anthony D. Blaom <[email protected]>"]
4-
version = "0.1.14"
4+
version = "0.1.15"
55

66
[deps]
77
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"

src/types.jl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,11 @@ _check_augmentable(support, probs) = _check_probs_01(probs) &&
239239
size(probs)[end] + 1 == length(support) ||
240240
throw(err_dim_augmented(support, probs))
241241

242+
err_incompatible_pool(support, classes) = ArgumentError(
243+
"Specified support, $support, not contained in "*
244+
"specified pool, $(levels(classes)). "
245+
)
246+
242247

243248
## AUGMENTING ARRAYS TO MAKE THEM PROBABILITY ARRAYS
244249

@@ -277,7 +282,7 @@ function _augment_probs(::Val{true},
277282
end
278283

279284
_array_or_scalar(x::Array) = x
280-
_array_or_scalar(x::AbstractArray) = copyto!(similar(Array{eltype(x)}, axes(x)), x)
285+
_array_or_scalar(x::AbstractArray) = copyto!(similar(Array{eltype(x)}, axes(x)), x)
281286
_array_or_scalar(x) = x
282287

283288
## CONSTRUCTORS - FROM DICTIONARY
@@ -453,14 +458,12 @@ function _UnivariateFinite(support,
453458
_support = classes(v)
454459
else
455460
_classes = classes(pool)
456-
issubset(support, _classes) ||
457-
error("Specified support, $support, not contained in "*
458-
"specified pool, $(levels(classes)). ")
461+
issubset(support, _classes) || throw(err_incompatible_pool(support, _classes))
459462
idxs = getindex.(
460-
Ref(CategoricalArrays.DataAPI.invrefpool(_classes)),
463+
Ref(CategoricalArrays.DataAPI.invrefpool(_classes)),
461464
support
462465
)
463-
_support = _classes[idxs]
466+
_support = _classes[idxs]
464467
end
465468

466469
# calls core method:

test/types.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ import CategoricalDistributions: classes
2424
@test_logs((:warn, r"No "),
2525
UnivariateFinite(['f', 'q', 's'], [0.7, 0.2, 0.1]))
2626

27+
junk = ["F", "Q", "S"]
28+
@test_throws(
29+
CategoricalDistributions.err_incompatible_pool(junk, classes(v)),
30+
UnivariateFinite(junk, [0.1, 0.9], pool=v),
31+
)
32+
2733
end
2834

2935
@testset "array constructors" begin
@@ -37,7 +43,7 @@ end
3743

3844
UnivariateFinite(supp, probs, pool=missing, augment=true);
3945

40-
# construction from pool and support does not
46+
# construction from pool and support does not
4147
# consist of categorical elements (See issue #34)
4248
v = categorical(["x", "x", "y", "z", "y", "z", "p"])
4349
probs1 = [0.1, 0.2, 0.7]
@@ -75,7 +81,7 @@ end
7581
v = categorical(['x', 'x', 'y', 'x', 'z', 'w'])
7682
probs_fillarray = FillArrays.Ones(100, 3)
7783
probs_array = ones(100, 3)
78-
84+
7985
probs1_fillarray = FillArrays.Fill(0.2, 100, 2)
8086
probs1_array = fill(0.2, 100, 2)
8187

@@ -88,7 +94,7 @@ end
8894
u1_from_fillarray = UnivariateFinite(
8995
['x', 'y', 'z'], probs1_fillarray, pool=v, augment=true
9096
)
91-
97+
9298
@test u_from_array.prob_given_ref == u_from_fillarray.prob_given_ref
9399
@test u1_from_array.prob_given_ref == u1_from_fillarray.prob_given_ref
94100

0 commit comments

Comments
 (0)