Repository: invenia/NamedDims.jl (julia)

Issue:
Linear Indexing on a multidimensional array, wrong names
Pointed out in https://github.com/mcabbott/AxisKeys.jl/issues/48

```julia
julia> nda = NamedDimsArray(rand(2,3), (:vars, :obs))
2×3 NamedDimsArray(::Matrix{Float64}, (:vars, :obs)):
        → obs
↓ vars  0.193787  0.705025  0.924788
        0.350784  0.428619  0.527309

julia> nda[:]
6-element NamedDimsArray(::Vector{Float64}, (:vars,)):
↓ vars  0.19378660323367924
        0.3507837608841804
        0.7050254989780798
        0.42861915061937106
        0.9247877011245385
        0.5273088922725788

julia> nda[1:2:end]
3-element NamedDimsArray(::Vector{Float64}, (:vars,)):
↓ vars  0.19378660323367924
        0.7050254989780798
        0.9247877011245385
        
julia> nda[[1,5,6,]]
3-element NamedDimsArray(::Vector{Float64}, (:vars,)):
↓ vars  0.19378660323367924
        0.9247877011245385
        0.5273088922725788
```

Linear Indexing always returns a AbstractVector.
It's dimension doesn't corespond to either of the existing dimensions of the array being indexed into.
But we apparently just assign it the first. See all the above examples
It's dimension does corespond to the dimension of the indexing vector.

So actally the following should have the name `foo`
```julia
julia> x[NamedDimsArray{(:foo,)}([1,4,5])]
3-element Vector{Float64}:
 0.4987215341030389
 0.18635552495009877
 0.4817820740518193
 ```

Pull request:
Possibly closes #158.

Patch:
diff --git a/src/name_core.jl b/src/name_core.jl
index 52c35ba..77c96ce 100644
--- a/src/name_core.jl
+++ b/src/name_core.jl
@@ -381,8 +381,13 @@ remaining_dimnames_from_indexing(dn::Tuple, inds::Tuple{Vararg{<:Integer}}) = ()
 remaining_dimnames_from_indexing(dn::Tuple, ci::Tuple{CartesianIndex}) = ()
 
 function remaining_dimnames_from_indexing(
-    dimnames::Tuple{<:Any,<:Any,Vararg}, inds::Tuple{T},
-) where {T<:Union{Base.LogicalIndex,AbstractVector{<:CartesianIndex}}}
+    dimnames::Tuple{<:Any,<:Any,Vararg},  # only for ndims(A) >= 2
+    inds::Tuple{T},
+) where {T<:Union{
+    Base.LogicalIndex,  # e.g. A[A .> 0]
+    AbstractVector{<:CartesianIndex},
+    AbstractVector{<:Integer},  # e.g. A[1:end]
+}}
     return ()
 end
 


Test patch:
diff --git a/test/name_core.jl b/test/name_core.jl
index 7952117..c399dd2 100644
--- a/test/name_core.jl
+++ b/test/name_core.jl
@@ -155,6 +155,8 @@ end
     @test remaining_dimnames_from_indexing((:a, :b), logical) === ()
     cart_vec = findall(x -> x>0.5, rand(2,3))
     @test remaining_dimnames_from_indexing((:a, :b), (cart_vec,)) === ()
+    int_vec = 1:6
+    @test remaining_dimnames_from_indexing((:a, :b), (int_vec,)) === ()
 end
 @testset "allocations: remaining_dimnames_from_indexing" begin
     @test 0 == @ballocated (()->remaining_dimnames_from_indexing((:a, :b, :c), (:,390,:)))()
diff --git a/test/wrapper_array.jl b/test/wrapper_array.jl
index 41ce815..68f2ba9 100644
--- a/test/wrapper_array.jl
+++ b/test/wrapper_array.jl
@@ -136,6 +136,15 @@ end
         # Vector{CartesianIndex{N}}: for N>1 this makes a new dim, like nda[nda .> 3]
         @test nda[findall(iseven, nda)] isa Vector
         @test dimnames(ndv[findall(iseven, ndv)]) == (:x,)
+
+        # ... as does a vector of integers:
+        @test nda[1:end] isa Vector
+        @test nda[collect(2:end)] isa Vector
+        @test dimnames(ndv[1:end]) == (:x,)
+
+        # ... or equivalent colon:
+        @test nda[:] isa Vector
+        @test dimnames(ndv[:]) == (:x,)
     end
 end