Skip to content

Commit

Permalink
Merge pull request #51 from ajkeller34/to_index_fix
Browse files Browse the repository at this point in the history
to_index now throws an ArgumentException instead of an UndefVarError …
  • Loading branch information
mbauman committed Oct 27, 2016
2 parents a63fd44 + 00815fb commit 040f115
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ end
idxs = Expr[:(Colon()) for d = 1:N]
names = axisnames(A)
for i=1:length(dims)
idxs[dims[i]] == :(Colon()) || return :(error("multiple indices provided on axis ", $(names[dims[i]])))
idxs[dims[i]] == :(Colon()) ||
return :(throw(ArgumentError(string("multiple indices provided ",
"on axis ", $(string(names[dims[i]]))))))
idxs[dims[i]] = :(I[$i].val)
end

Expand Down
5 changes: 5 additions & 0 deletions test/indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,8 @@ axy = @inferred(A[Axis{:y}])
@test isa(axy, Axis{:y})
@test axy.val == 1:5
@test_throws ArgumentError A[Axis{:z}]

# Test for the expected exception type given repeated axes
A = AxisArray(rand(2,2), :x, :y)
@test_throws ArgumentError A[Axis{:x}(1), Axis{:x}(1)]
@test_throws ArgumentError A[Axis{:y}(1), Axis{:y}(1)]

0 comments on commit 040f115

Please sign in to comment.