Skip to content

Commit 040f115

Browse files
authored
Merge pull request #51 from ajkeller34/to_index_fix
to_index now throws an ArgumentException instead of an UndefVarError …
2 parents a63fd44 + 00815fb commit 040f115

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/indexing.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ end
107107
idxs = Expr[:(Colon()) for d = 1:N]
108108
names = axisnames(A)
109109
for i=1:length(dims)
110-
idxs[dims[i]] == :(Colon()) || return :(error("multiple indices provided on axis ", $(names[dims[i]])))
110+
idxs[dims[i]] == :(Colon()) ||
111+
return :(throw(ArgumentError(string("multiple indices provided ",
112+
"on axis ", $(string(names[dims[i]]))))))
111113
idxs[dims[i]] = :(I[$i].val)
112114
end
113115

test/indexing.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,8 @@ axy = @inferred(A[Axis{:y}])
136136
@test isa(axy, Axis{:y})
137137
@test axy.val == 1:5
138138
@test_throws ArgumentError A[Axis{:z}]
139+
140+
# Test for the expected exception type given repeated axes
141+
A = AxisArray(rand(2,2), :x, :y)
142+
@test_throws ArgumentError A[Axis{:x}(1), Axis{:x}(1)]
143+
@test_throws ArgumentError A[Axis{:y}(1), Axis{:y}(1)]

0 commit comments

Comments
 (0)