Phuoc
Phuoc

Reputation: 1093

Cannot broadcast isna. for DataArrays.DataArray{String}

Is there a way to fix/allow broadcast for isna for DataArrays.DataArray{String}? I got the following error when trying to do so:

julia> using DataFrames
julia> a=@data(["1776",   "1895",   " 0",   " 1774",    NA    ])
5-element DataArrays.DataArray{String,1}:
 "1776" 
 "1895" 
 " 0"   
 " 1774"
 NA     

julia> isna.(a)
ERROR: MethodError: Cannot `convert` an object of type Bool to an object of type String
This may have arisen from a call to the constructor String(...),
since type constructors fall back to convert methods.
 in macro expansion at /home/ngphuoc/.julia/v0.5/DataArrays/src/broadcast.jl:60 [inlined]
 in macro expansion at ./cartesian.jl:64 [inlined]
 in (::DataArrays.#_F_#203)(::DataArrays.DataArray{String,1}, ::DataArrays.DataArray{String,1}) at /home/ngphuoc/.julia/v0.5/DataArrays/src/broadcast.jl:130
 in broadcast!(::Function, ::DataArrays.DataArray{String,1}, ::DataArrays.DataArray{String,1}) at /home/ngphuoc/.julia/v0.5/DataArrays/src/broadcast.jl:229
 in databroadcast(::Function, ::DataArrays.DataArray{String,1}, ::Vararg{DataArrays.DataArray{String,1},N}) at /home/ngphuoc/.julia/v0.5/DataArrays/src/broadcast.jl:235
 in broadcast(::Function, ::DataArrays.DataArray{String,1}) at /home/ngphuoc/.julia/v0.5/DataArrays/src/broadcast.jl:296
 in eval_user_input(::Any, ::Base.REPL.REPLBackend) at ./REPL.jl:64
 in macro expansion at ./REPL.jl:95 [inlined]
 in (::Base.REPL.##3#4{Base.REPL.REPLBackend})() at ./event.jl:68

Upvotes: 1

Views: 92

Answers (1)

mbauman
mbauman

Reputation: 31342

On 0.5, DataArrays erroneously assumes that the resulting element types of broadcast will simply follow promotion rules. This bug has since been fixed in 0.6. Updating would be your best course of action.

Of course, on 0.5, there still exists the old vectorized isna method; that's probably your best option if you must stay there for now. It's since been deprecated in favor of the isna.(a) broadcast on 0.6.

julia> isna(a)
5-element BitArray{1}:
 false
 false
 false
 false
  true

Upvotes: 1

Related Questions