Skip to content
This repository was archived by the owner on May 4, 2019. It is now read-only.
This repository was 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

Description

@grst

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions