@@ -210,6 +210,13 @@ acc = zeros(Int, 4, 1, 2)
210210Base. mapreducedim! (x-> x> 5 , + , acc, A3)
211211@test acc == reshape ([1 3 ; 2 3 ; 2 3 ; 2 3 ], 4 , 1 , 2 )
212212
213+ # Value axistraits
214+ @testset for typ in (IL. IntLike, Complex{Float32}, DateTime, String, Symbol, Int)
215+ @test AxisArrays. axistrait (Axis{:foo , Vector{AxisArrays. ExactValue{typ}}}) ===
216+ AxisArrays. axistrait (Axis{:foo , Vector{AxisArrays. TolValue{typ}}}) ===
217+ AxisArrays. axistrait (Axis{:bar , Vector{typ}})
218+ end
219+
213220# Indexing by value using `atvalue`
214221A = AxisArray ([1 2 ; 3 4 ], Axis {:x} ([1.0 ,4.0 ]), Axis {:y} ([2.0 ,6.1 ]))
215222@test @inferred (A[atvalue (1.0 )]) == @inferred (A[atvalue (1.0 ), :]) == [1 ,2 ]
@@ -259,6 +266,16 @@ A = AxisArray([1 2; 3 4], Axis{:x}([:a, :b]), Axis{:y}(["c", "d"]))
259266@test @inferred (A[Axis {:x} (atvalue (:b ))]) == [3 ,4 ]
260267@test @inferred (A[Axis {:y} (atvalue (" d" ))]) == [2 ,4 ]
261268
269+ # Index by mystery types categorically
270+ struct Foo
271+ x
272+ end
273+ A = AxisArray (1 : 10 , Axis {:x} (map (Foo, 1 : 10 )))
274+ @test A[map (Foo, 3 : 6 )] == collect (3 : 6 )
275+ @test_throws ArgumentError A[map (Foo, 3 : 11 )]
276+ @test A[Foo (4 )] == 4
277+ @test_throws ArgumentError A[Foo (0 )]
278+
262279# Test using dates
263280using Base. Dates: Day, Month
264281A = AxisArray (1 : 365 , Date (2017 ,1 ,1 ): Date (2017 ,12 ,31 ))
0 commit comments