Skip to content

Commit a78415a

Browse files
authored
Replace deprecated key2dim with name2dim (#84)
* Don't use deprecated key2dim * Rename internal _key2dim to _name2dim * Increment patch number
1 parent 380d2e5 commit a78415a

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "InferenceObjects"
22
uuid = "b5cf5a8d-e756-4ee3-b014-01d49d192c00"
33
authors = ["Seth Axen <[email protected]> and contributors"]
4-
version = "0.4.2"
4+
version = "0.4.3"
55

66
[deps]
77
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"

src/InferenceObjects.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const SCHEMA_GROUPS = (
2626
:warmup_log_likelihood,
2727
)
2828
const SCHEMA_GROUPS_DICT = Dict(n => i for (i, n) in enumerate(SCHEMA_GROUPS))
29-
const DEFAULT_SAMPLE_DIMS = Dimensions.key2dim((:draw, :chain))
29+
const DEFAULT_SAMPLE_DIMS = Dimensions.name2dim((:draw, :chain))
3030
const DEFAULT_DRAW_DIM = 1
3131
const DEFAULT_CHAIN_DIM = 2
3232

src/dimensions.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
has_all_sample_dims(dims) = all(Dimensions.hasdim(dims, DEFAULT_SAMPLE_DIMS))
22

3-
# Like Dimensions.key2dim but doesn't allow users to inject their own dimensions using
3+
# Like Dimensions.name2dim but doesn't allow users to inject their own dimensions using
44
# Dimensions.@dim. See https://github.com/arviz-devs/InferenceObjects.jl/issues/37
5-
_key2dim(d::Symbol) = Dimensions.Dim{d}(LookupArrays.NoLookup())
6-
_key2dim(d::Tuple) = map(_key2dim, d)
7-
_key2dim(d) = d
5+
_name2dim(d::Symbol) = Dimensions.Dim{d}(LookupArrays.NoLookup())
6+
_name2dim(d::Tuple) = map(_name2dim, d)
7+
_name2dim(d) = d
88

99
# make sure dim has a lookup value accessible with `val`
1010
_valdim(d) = d
@@ -30,7 +30,7 @@ Convert `dim`, `coords`, and `axis` to a `Dimension` object.
3030
- `axis`: A default axis to be used if `coords` and `dim` indices are not provided.
3131
"""
3232
function as_dimension(dim, coords, axis)
33-
cdim = _valdim(_key2dim(dim))
33+
cdim = _valdim(_name2dim(dim))
3434
val = LookupArrays.val(cdim)
3535
inds = val isa Union{Colon,LookupArrays.NoLookup} ? axis : val
3636
coords_inds = get(coords, Dimensions.name(cdim), inds)
@@ -64,7 +64,7 @@ Generate `DimensionsionalData.Dimension` objects for each dimension of `array`.
6464
function generate_dims(array, name; dims=(), coords=(;), default_dims=())
6565
num_default_dims = length(default_dims)
6666
if length(dims) + num_default_dims > ndims(array)
67-
dim_names = Dimensions.name(_key2dim((default_dims..., dims...)))
67+
dim_names = Dimensions.name(_name2dim((default_dims..., dims...)))
6868
throw(
6969
DimensionMismatch(
7070
"Provided dimensions $dim_names more than dimensions of array: $(ndims(array))",

test/dimensions.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ Dimensions.@dim foo "foo"
2626
))
2727
end
2828

29-
@testset "_key2dim" begin
29+
@testset "_name2dim" begin
3030
@testset for k in (:chain, :draw, :foo)
31-
@test InferenceObjects._key2dim(k) === Dim{k}(NoLookup())
32-
@test @inferred(InferenceObjects._key2dim(Dim{k})) === Dim{k}
33-
@test @inferred(InferenceObjects._key2dim(Dim{k}())) === Dim{k}()
34-
@test @inferred(InferenceObjects._key2dim(Dim{k}(1:4))) == Dim{k}(1:4)
31+
@test InferenceObjects._name2dim(k) === Dim{k}(NoLookup())
32+
@test @inferred(InferenceObjects._name2dim(Dim{k})) === Dim{k}
33+
@test @inferred(InferenceObjects._name2dim(Dim{k}())) === Dim{k}()
34+
@test @inferred(InferenceObjects._name2dim(Dim{k}(1:4))) == Dim{k}(1:4)
3535
end
36-
@test InferenceObjects._key2dim((:chain, :draw, :foo)) ===
36+
@test InferenceObjects._name2dim((:chain, :draw, :foo)) ===
3737
(Dim{:chain}(NoLookup()), Dim{:draw}(NoLookup()), Dim{:foo}(NoLookup()))
3838
end
3939

0 commit comments

Comments
 (0)