On Thu, Dec 24, 2015 at 8:22 PM, Yichao Yu <[email protected]> wrote:
> On Thu, Dec 24, 2015 at 7:51 PM, Ismael Venegas Castelló
> <[email protected]> wrote:
>> Something like this:
>>
>> julia> df = DataFrame(x = Int[1:10; typemax(Int8)]);
>>
>> julia> eltype(df[:x])
>> Int64
>>
>> julia> df[:x] = Int8[df[:x]...];
>>
>> julia> eltype(df[:x])
>> Int8
>>
>> julia> df = DataFrame(x = Int[1:10; typemax(Int8) + 1]);
>>
>> julia> eltype(df[:x])
>> Int64
>>
>> julia> df[:x] = Int8[df[:x]...];
>> ERROR: InexactError()
>>  in getindex at array.jl:167
>
> It's a bad idea to splat an array. Use `map(Int8, x)` instead.

There seems to be a inference regression with `map`[1]. In the mean
time, either `round(Int8, x)` or `[Int8(e) for e in x]` should work.


[1] https://github.com/JuliaLang/julia/issues/14482

>
>>
>>
>>
>> You get the error for free!
>>
>> El jueves, 24 de diciembre de 2015, 5:02:14 (UTC-6), Min-Woong Sohn
>> escribió:
>>>
>>> I want to reduce the amount of memory used by a dataframe that has lots of
>>> binary variables. What is the best way to achieve this? For example, how can
>>> I convert a variable from Int64 to Int8 in a dataframe.
>>>
>>> Thanks

Reply via email to