Skip to content
This repository has been archived by the owner on May 4, 2019. It is now read-only.

Broadcast on data array fails when changing the data type. #261

Open
grst opened this issue Jun 2, 2017 · 0 comments
Open

Broadcast on data array fails when changing the data type. #261

grst opened this issue Jun 2, 2017 · 0 comments

Comments

@grst
Copy link

grst commented Jun 2, 2017

When attempting to broadcast a function to a data array which has a different return type than input type this fails with:

MethodError: Cannot `convert` an object of type Float64 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/sturm/.julia/v0.5/DataArrays/src/broadcast.jl:60 [inlined]
 in macro expansion at ./cartesian.jl:64 [inlined]
 in (::DataArrays.#_F_#204)(::DataArrays.DataArray{String,1}, ::DataArrays.DataArray{String,1}) at /home/sturm/.julia/v0.5/DataArrays/src/broadcast.jl:130
 in broadcast!(::Function, ::DataArrays.DataArray{String,1}, ::DataArrays.DataArray{String,1}) at /home/sturm/.julia/v0.5/DataArrays/src/broadcast.jl:229
 in databroadcast(::Function, ::DataArrays.DataArray{String,1}, ::Vararg{DataArrays.DataArray{String,1},N}) at /home/sturm/.julia/v0.5/DataArrays/src/broadcast.jl:235
 in (::###346#72{DataFrames.DataFrame})(::DataArrays.DataArray{String,1}) at /home/sturm/.julia/v0.5/DataFramesMeta/src/DataFramesMeta.jl:55

Here is a minimal working example:

function return_float(x)
    42.0 
end

function return_string(x)
    "42"
end

da = DataArray(["1", "2"])

# works
return_string.(da)

# fails
return_float.(da)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant