Le dimanche 29 mars 2015 à 09:46 -0700, Philip Tellis a écrit :
> On Sunday, March 29, 2015 at 6:47:32 AM UTC-4, Milan Bouchet-Valat
> wrote:
> 
>         Le samedi 28 mars 2015 à 21:35 -0700, Philip Tellis a écrit : 
>         
>         > I've written the following code:
>         > 
>         > 
>         > import Base.convert
>         > function convert(::Type{UTF8String}, x::Int64)
>         >     return utf8(string(x))
>         > end
>         > println(convert(UTF8String, 10))
>         > println(convert(Array{UTF8String, 1}, [10]))
>         > 
>         > 
>         > 
>         > The intent is to convert an Array of Int64 into an Array of
>         > UTF8String.
>         > 
>         > 
>         > The first println works correctly and converts 10 into "10"
>         > 
>         > 
>         > The second println should print an array of ["10"], but
>         > instead gives me the following error:
>         > 
>         > 
>         > 
>         > type: arrayset: expected UTF8String, got ASCIIString
>         > while loading In[41], in expression starting on line 6
>         > 
>         >  in copy! at abstractarray.jl:149
>         >  in convert at array.jl:220
>         > 
>         > 
>         > 
>         > I'm using Julia 0.3.6
>         > 
>         > 
>         > Any idea on what I'm doing wrong?
>         
>         This works perfectly fine for me with 0.3.6 on Linux. Could
>         you try at the Julia-REPL instead of IJulia (as you appear to
>         be using). Can you post the output of versioninfo()?
>         
>         
>         (FWIW, I'm not sure what you're trying to do is a great idea.
>         convert is not defined that way because moving between numbers
>         and strings is not considered a mere conversion, i.e. it
>         should never happen automatically. Better give that function a
>         different name, or use map() or a comprehension.)
>         
>         
>         
> 
> 
> 
> 
> You're right, it does work on the julia REPL, so there could be
> something else in my running IJulia session that's interfering with
> it.
> 
> 
> As to my actual problem, what I have is a DataFrame with two columns,
> one a DataArray{UTF8String, 1} and the other a DataArray{Int64, 1},
> and I need to concatenate the two columns, but I can't do this because
> the * operator does not work with UTF8String & Int64.  I suppose one
> option is for me to just cast the Int64 to a string in my SQL query
> that produces the dataframe.
Well, you don't need to overload convert to do that. One of the many
solutions, assuming a and b are the two columns:
df[:c] = ASCIIString[string(r[:a]) * r[:b] for r in eachrow(df)]


Regards


> I could also just concatenate the columns in SQL, but that would
> significantly increase the amount of data sent over the network
> between my db node and my julia compute node. 

Reply via email to