JuliaArrays / JuliaArrays/AxisArrays.jl

Broken indexing for axis with eltype Dates.Date

Open
#212 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
207
Forks
41
PR merge metrics
No merged PRs in 30d

Description

Indexing into an axis array with an axis of eltype date using a range of eltype date as an index throws. I believe this is a bug.

julia> using AxisArrays, Test

julia> @testset for axis in [1:3, 'a':'c', Date(0):Day(1):Date(0,1,3)]
           a = AxisArray(1:3, axis)
           @test a[axis[1]] == 1
           @test a[axis[2]] == 2
           @test a[axis[3]] == 3
           @test a[:] == 1:3
           @test a[axis] == 1:3
       end
Test Summary: | Pass  Total  Time
axis = 1:3    |    5      5  0.0s
Test Summary:    | Pass  Total  Time
axis = 'a':1:'c' |    5      5  0.0s
axis = Date("0000-01-01"):Day(1):Date("0000-01-03"): Error During Test at REPL[136]:7
  Test threw exception
  Expression: a[axis] == 1:3
  ArgumentError: unable to check bounds for indices of type Date
  Stacktrace:
    [1] checkindex(#unused#::Type{Bool}, inds::Base.OneTo{Int64}, i::Date)
      @ Base ./abstractarray.jl:766
    [2] checkindex
      @ ./abstractarray.jl:773 [inlined]
    [3] checkbounds
      @ ./abstractarray.jl:694 [inlined]
    [4] checkbounds
      @ ./abstractarray.jl:709 [inlined]
    [5] _getindex
      @ ./multidimensional.jl:860 [inlined]
    [6] getindex
      @ ./abstractarray.jl:1294 [inlined]
    [7] getindex_converted
      @ ~/.julia/packages/AxisArrays/v7vf4/src/indexing.jl:133 [inlined]
    [8] getindex(A::AxisArray{Int64, 1, UnitRange{Int64}, Tuple{Axis{:row, StepRange{Date, Day}}}}, idxs::StepRange{Date, Day})
      @ AxisArrays ~/.julia/packages/AxisArrays/v7vf4/src/indexing.jl:123
    [9] macro expansion
      @ ~/.julia/dev/julia_master/usr/share/julia/stdlib/v1.9/Test/src/Test.jl:477 [inlined]
   [10] macro expansion
      @ ./REPL[136]:7 [inlined]
   [11] top-level scope
      @ ~/.julia/dev/julia_master/usr/share/julia/stdlib/v1.9/Test/src/Test.jl:1584 [inlined]
   [12] top-level scope
      @ ./REPL[136]:0
Test Summary:                                       | Pass  Error  Total  Time
axis = Date("0000-01-01"):Day(1):Date("0000-01-03") |    4      1      5  0.0s

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/indexing.jl around getindex and getindex_converted, which appear in the reported stack trace. Reproduce the failure with the Date range example from the issue, then add or update a regression test for indexing an axis with eltype Dates.Date. Done means the Date case passes alongside the integer and character cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.