Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deprecated int method fails for non-concrete arrays of strings #12847

Closed
peeterjoot opened this issue Aug 28, 2015 · 3 comments
Closed

deprecated int method fails for non-concrete arrays of strings #12847

peeterjoot opened this issue Aug 28, 2015 · 3 comments

Comments

@peeterjoot
Copy link

I asked a question like the following on stackoverflow and Matt B asked me to report this as an issue, stating "The deprecated method should work and the warning message should print a valid suggestion"

I'm unable to convert integer regular expression captures values to an array of integers in Julia 0.4.

In Julia 0.3 I could do this with int(), basically like:

c = ["1", "2"] ;
int(c)

But in Julia 0.4, this works for regular strings:

julia> c = ["1", "2"] ;

julia> int(c)
2-element Array{Int64,1}:
 1
 2

but doesn't work with substrings (i.e. regex captures):

re_dcIV = r"^
([IV])(\S+)\s+
(\d+)\s+
(\d+)\s+
DC\s+
(\S+)\s*$"x ;

line = "V1 1 2 DC 1" ;

m = match( re_dcIV, line ) ;

c = m.captures ;
println( "$c\n" ) ;

nodes = int(c[3:4]) ;

which produces:

julia> nodes = int(c[3:4]) ;
WARNING: int(x::AbstractArray) is deprecated, use round(Int64,x) instead.
 in depwarn at deprecated.jl:63
 in int at deprecated.jl:49
while loading no file, in expression starting on line 0
ERROR: MethodError: `round` has no method matching round(::Type{Int64}, ::SubString{UTF8String})
Closest candidates are:
  round{T<:Integer}(::Type{T<:Integer}, ::Integer)
  round{T<:Integer}(::Type{T<:Integer}, ::Float16)
  round{T<:Union{Signed,Unsigned}}(::Type{T<:Union{Signed,Unsigned}}, ::Base.MPFR.BigFloat)
  ...
 in round at floatfuncs.jl:72
 in int at deprecated.jl:51

The type of the capture array is:

Union{SubString{UTF8String},Void}["V","1","1","2","1"]

and I'm not able to execute int(c[3:4]) on a subset of that beastie.

@mbauman mbauman changed the title unable to convert integer regular expression captures values to an array of integers in Julia 0.4 deprecated int method fails for non-concrete arrays of strings Aug 28, 2015
@yuyichao
Copy link
Contributor

int is deprecated. Use

julia> map(x->parse(Int, x), c[3:4])
2-element Array{Int64,1}:
 1
 2

The deprecated isue is wrong though.

@mbauman
Copy link
Member

mbauman commented Aug 28, 2015

Thanks! More specifically:

# Julia-0.3
julia> int(Any["1","2"])
2-element Array{Int64,1}:
 1
 2

# Julia-0.4
julia> int(Any["1","2"])
WARNING: int(x::AbstractArray) is deprecated, use round(Int64,x) instead.
 in depwarn at /Users/mbauman/Applications/julia-0.4/lib/julia/sys.dylib
 in int at deprecated.jl:49
while loading no file, in expression starting on line 0
ERROR: MethodError: `round` has no method matching round(::Type{Int64}, ::ASCIIString)
Closest candidates are:
  round{T<:Integer}(::Type{T<:Integer}, ::Integer)
  round{T<:Integer}(::Type{T<:Integer}, ::Float16)
  round{T<:Union{Signed,Unsigned}}(::Type{T<:Union{Signed,Unsigned}}, ::Base.MPFR.BigFloat)
  ...
 in round at floatfuncs.jl:72
 in int at deprecated.jl:51

JeffBezanson added a commit that referenced this issue Sep 16, 2015
(cherry picked from commit ab1d09b)
@tkelman
Copy link
Contributor

tkelman commented Sep 16, 2015

backported in #13107

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants