parse.(Int64, x)

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

parse.(Int64, x)

David Anthoff

I just tried to use the new dot syntax for vectorising function calls in order to convert an array of strings into an array of Int64. For example, if this would work, it would be very, very handy:

 

x = [“1”, “2”, “3”]

parse.(Int64, x)

 

Right now I get an error, but I wonder whether this could be enabled somehow in this new framework? If this would work for all sorts of parsing, type conversions etc. it would just be fantastic. Especially when working DataFrames and one is in the first phase of cleaning up data types of columns etc. this would make for a very nice and short notation.

 

Thanks,

David

 

--

David Anthoff

University of California, Berkeley

 

http://www.david-anthoff.com

 

Reply | Threaded
Open this post in threaded view
|

Re: parse.(Int64, x)

John Myles White
I would be careful combining element-wise function application with partial function application. Why not use map instead?

On Wednesday, June 15, 2016 at 3:47:05 PM UTC-7, David Anthoff wrote:

I just tried to use the new dot syntax for vectorising function calls in order to convert an array of strings into an array of Int64. For example, if this would work, it would be very, very handy:

 

x = [“1”, “2”, “3”]

parse.(Int64, x)

 

Right now I get an error, but I wonder whether this could be enabled somehow in this new framework? If this would work for all sorts of parsing, type conversions etc. it would just be fantastic. Especially when working DataFrames and one is in the first phase of cleaning up data types of columns etc. this would make for a very nice and short notation.

 

Thanks,

David

 

--

David Anthoff

University of California, Berkeley

 

<a href="http://www.david-anthoff.com" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.david-anthoff.com\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHPDijM7QgcCRbDWt_-VR5r_HnDGg&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.david-anthoff.com\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHPDijM7QgcCRbDWt_-VR5r_HnDGg&#39;;return true;">http://www.david-anthoff.com

 

Reply | Threaded
Open this post in threaded view
|

Re: parse.(Int64, x)

David Anthoff

map of course works, but it is quite verbose. I’ve been working a group of new julia users lately, many of them from other languages like R, Python etc., and they roll their eyes when something that simple takes

 

df[:x] = map(q->parse(Int64,q), df[:x])

 

It just is quite complicated for something pretty simple… Maybe there are other simple constructs for this?

 

Thanks,

David

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of John Myles White
Sent: Wednesday, June 15, 2016 3:53 PM
To: julia-users <[hidden email]>
Subject: [julia-users] Re: parse.(Int64, x)

 

I would be careful combining element-wise function application with partial function application. Why not use map instead?

On Wednesday, June 15, 2016 at 3:47:05 PM UTC-7, David Anthoff wrote:

I just tried to use the new dot syntax for vectorising function calls in order to convert an array of strings into an array of Int64. For example, if this would work, it would be very, very handy:

 

x = [“1”, “2”, “3”]

parse.(Int64, x)

 

Right now I get an error, but I wonder whether this could be enabled somehow in this new framework? If this would work for all sorts of parsing, type conversions etc. it would just be fantastic. Especially when working DataFrames and one is in the first phase of cleaning up data types of columns etc. this would make for a very nice and short notation.

 

Thanks,

David

 

--

David Anthoff

University of California, Berkeley

 

http://www.david-anthoff.com

 

Reply | Threaded
Open this post in threaded view
|

Re: parse.(Int64, x)

Tony Kelman
Try parse.([Int64], x)
note that the output will be an Array{Any} because issue #4883 hasn't been fixed yet. The issue here is that broadcast doesn't treat types as "scalar-like."


On Wednesday, June 15, 2016 at 4:19:09 PM UTC-7, David Anthoff wrote:

map of course works, but it is quite verbose. I’ve been working a group of new julia users lately, many of them from other languages like R, Python etc., and they roll their eyes when something that simple takes

 

df[:x] = map(q->parse(Int64,q), df[:x])

 

It just is quite complicated for something pretty simple… Maybe there are other simple constructs for this?

 

Thanks,

David

 

From: <a href="javascript:" target="_blank" gdf-obfuscated-mailto="5sUPyaDLBgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">julia...@... [mailto:<a href="javascript:" target="_blank" gdf-obfuscated-mailto="5sUPyaDLBgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">julia...@googlegroups.com] On Behalf Of John Myles White
Sent: Wednesday, June 15, 2016 3:53 PM
To: julia-users <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="5sUPyaDLBgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">julia...@...>
Subject: [julia-users] Re: parse.(Int64, x)

 

I would be careful combining element-wise function application with partial function application. Why not use map instead?

On Wednesday, June 15, 2016 at 3:47:05 PM UTC-7, David Anthoff wrote:

I just tried to use the new dot syntax for vectorising function calls in order to convert an array of strings into an array of Int64. For example, if this would work, it would be very, very handy:

 

x = [“1”, “2”, “3”]

parse.(Int64, x)

 

Right now I get an error, but I wonder whether this could be enabled somehow in this new framework? If this would work for all sorts of parsing, type conversions etc. it would just be fantastic. Especially when working DataFrames and one is in the first phase of cleaning up data types of columns etc. this would make for a very nice and short notation.

 

Thanks,

David

 

--

David Anthoff

University of California, Berkeley

 

<a href="http://www.david-anthoff.com" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.david-anthoff.com\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHPDijM7QgcCRbDWt_-VR5r_HnDGg&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.david-anthoff.com\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHPDijM7QgcCRbDWt_-VR5r_HnDGg&#39;;return true;">http://www.david-anthoff.com

 

Reply | Threaded
Open this post in threaded view
|

Re: parse.(Int64, x)

Milan Bouchet-Valat
Le mercredi 15 juin 2016 à 17:28 -0700, Tony Kelman a écrit :
> Try parse.([Int64], x)
> note that the output will be an Array{Any} because issue #4883 hasn't
> been fixed yet. The issue here is that broadcast doesn't treat types
> as "scalar-like."
Is the latter a separate bug? Should we open an issue for that?


> > map of course works, but it is quite verbose. I’ve been working a
> > group of new julia users lately, many of them from other languages
> > like R, Python etc., and they roll their eyes when something that
> > simple takes
> >  
> > df[:x] = map(q->parse(Int64,q), df[:x])
> >  
> > It just is quite complicated for something pretty simple… Maybe
> > there are other simple constructs for this?
> >  
> > Thanks,
> > David
> >  
> > From: [hidden email] [mailto:[hidden email]]
> > On Behalf Of John Myles White
> > Sent: Wednesday, June 15, 2016 3:53 PM
> > To: julia-users <[hidden email]>
> > Subject: [julia-users] Re: parse.(Int64, x)
> >  
> > I would be careful combining element-wise function application with
> > partial function application. Why not use map instead?
> >
> > On Wednesday, June 15, 2016 at 3:47:05 PM UTC-7, David Anthoff
> > wrote:
> > I just tried to use the new dot syntax for vectorising function
> > calls in order to convert an array of strings into an array of
> > Int64. For example, if this would work, it would be very, very
> > handy:
> >  
> > x = [“1”, “2”, “3”]
> > parse.(Int64, x)
> >  
> > Right now I get an error, but I wonder whether this could be
> > enabled somehow in this new framework? If this would work for all
> > sorts of parsing, type conversions etc. it would just be fantastic.
> > Especially when working DataFrames and one is in the first phase of
> > cleaning up data types of columns etc. this would make for a very
> > nice and short notation.
> >  
> > Thanks,
> > David
> >  
> > --
> > David Anthoff
> > University of California, Berkeley
> >  
> > http://www.david-anthoff.com
> >  
> >
Reply | Threaded
Open this post in threaded view
|

Re: parse.(Int64, x)

David Anthoff
https://github.com/JuliaLang/julia/issues/16966

> -----Original Message-----
> From: [hidden email] [mailto:julia-
> [hidden email]] On Behalf Of Milan Bouchet-Valat
> Sent: Thursday, June 16, 2016 1:33 AM
> To: [hidden email]
> Subject: Re: [julia-users] Re: parse.(Int64, x)
>
> Le mercredi 15 juin 2016 à 17:28 -0700, Tony Kelman a écrit :
> > Try parse.([Int64], x)
> > note that the output will be an Array{Any} because issue #4883 hasn't
> > been fixed yet. The issue here is that broadcast doesn't treat types
> > as "scalar-like."
> Is the latter a separate bug? Should we open an issue for that?
>
>
> > > map of course works, but it is quite verbose. I’ve been working a
> > > group of new julia users lately, many of them from other languages
> > > like R, Python etc., and they roll their eyes when something that
> > > simple takes
> > >
> > > df[:x] = map(q->parse(Int64,q), df[:x])
> > >
> > > It just is quite complicated for something pretty simple… Maybe
> > > there are other simple constructs for this?
> > >
> > > Thanks,
> > > David
> > >
> > > From: [hidden email] [mailto:[hidden email]]
> > > On Behalf Of John Myles White
> > > Sent: Wednesday, June 15, 2016 3:53 PM
> > > To: julia-users <[hidden email]>
> > > Subject: [julia-users] Re: parse.(Int64, x)
> > >
> > > I would be careful combining element-wise function application with
> > > partial function application. Why not use map instead?
> > >
> > > On Wednesday, June 15, 2016 at 3:47:05 PM UTC-7, David Anthoff
> > > wrote:
> > > I just tried to use the new dot syntax for vectorising function
> > > calls in order to convert an array of strings into an array of
> > > Int64. For example, if this would work, it would be very, very
> > > handy:
> > >
> > > x = [“1”, “2”, “3”]
> > > parse.(Int64, x)
> > >
> > > Right now I get an error, but I wonder whether this could be enabled
> > > somehow in this new framework? If this would work for all sorts of
> > > parsing, type conversions etc. it would just be fantastic.
> > > Especially when working DataFrames and one is in the first phase of
> > > cleaning up data types of columns etc. this would make for a very
> > > nice and short notation.
> > >
> > > Thanks,
> > > David
> > >
> > > --
> > > David Anthoff
> > > University of California, Berkeley
> > >
> > > http://www.david-anthoff.com
> > >
> > >