JuliaArrays / JuliaArrays/AxisArrays.jl

AxisArray broadcast container type

Open
#128 8 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

Currently AxisArrays do not use the container type information from the parent when working with broadcast. Typically this is fine but in some cases this can raise an exception:

julia> using DataArrays, AxisArrays

julia> a = AxisArray(@data([1, NA, 3]), 'a':'c')
1-dimensional AxisArray{Int64,1,...} with axes:
    :row, 'a':1:'c'
And data, a 3-element DataArrays.DataArray{Int64,1}:
 1
  NA
 3

julia> parent(a) .== 1
3-element DataArrays.DataArray{Bool,1}:
  true
      NA
 false

julia> a .== 1
ERROR: MethodError: Cannot `convert` an object of type DataArrays.NAtype to an object of type Bool
This may have arisen from a call to the constructor Bool(...),
since type constructors fall back to convert methods.
Stacktrace:
 [1] setindex!(::Array{Bool,1}, ::DataArrays.NAtype, ::Int64) at ./array.jl:549
 [2] macro expansion at ./broadcast.jl:180 [inlined]
 [3] macro expansion at ./simdloop.jl:73 [inlined]
 [4] macro expansion at ./broadcast.jl:174 [inlined]
 [5] _broadcast!(::##1#2, ::BitArray{1}, ::Tuple{Tuple{Bool}}, ::Tuple{Tuple{Int64}}, ::AxisArrays.AxisArray{Int64,1,DataArrays.DataArray{Int64,1},Tuple{AxisArrays.Axis{:row,StepRange{Char,Int64}}}}, ::Tuple{}, ::Type{Val{0}}, ::CartesianRange{CartesianIndex{1}}) at ./broadcast.jl:162
 [6] broadcast_t(::Function, ::Type{Bool}, ::Tuple{Base.OneTo{Int64}}, ::CartesianRange{CartesianIndex{1}}, ::AxisArrays.AxisArray{Int64,1,DataArrays.DataArray{Int64,1},Tuple{AxisArrays.Axis{:row,StepRange{Char,Int64}}}}) at ./broadcast.jl:279
 [7] broadcast_c at ./broadcast.jl:314 [inlined]
 [8] broadcast(::Function, ::AxisArrays.AxisArray{Int64,1,DataArrays.DataArray{Int64,1},Tuple{AxisArrays.Axis{:row,StepRange{Char,Int64}}}}) at ./broadcast.jl:434

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 by running the supplied Julia reproduction with DataArrays and AxisArrays, then trace how AxisArray values are handled during broadcast and how parent container type information is selected. Done means the shown a .== 1 operation no longer raises the NAtype-to-Bool exception and preserves the appropriate parent-container behavior.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.