Skip to content

Commit

Permalink
Deprecate float(::String)
Browse files Browse the repository at this point in the history
Fixes #24219
  • Loading branch information
ararslan committed Oct 20, 2017
1 parent b170573 commit 43e18a6
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
4 changes: 4 additions & 0 deletions base/deprecated.jl
Expand Up @@ -1893,6 +1893,10 @@ end
# issue #24006
@deprecate linearindices(s::AbstractString) eachindex(s)

# Issue 24219
@deprecate float(x::AbstractString) parse(Float64, x)
@deprecate float(a::AbstractArray{<:AbstractString}) parse.(Float64, a)

# END 0.7 deprecations

# BEGIN 1.0 deprecations
Expand Down
4 changes: 0 additions & 4 deletions base/parse.jl
Expand Up @@ -236,10 +236,6 @@ function parse(::Type{T}, s::AbstractString) where T<:AbstractFloat
return unsafe_get(result)
end

float(x::AbstractString) = parse(Float64,x)

float(a::AbstractArray{<:AbstractString}) = map!(float, similar(a,typeof(float(0))), a)

## interface to parser ##

"""
Expand Down
2 changes: 1 addition & 1 deletion test/perf/kernel/json.jl
Expand Up @@ -132,7 +132,7 @@ function parse_json(strng::AbstractString)
end
delta = m.offset + length(m.match)
pos = pos + delta -1
return float(m.match)
return parse(Float64, m.match)
end

function parse_value()
Expand Down
2 changes: 1 addition & 1 deletion test/strings/basic.jl
Expand Up @@ -176,7 +176,7 @@ let s = "x\u0302"
end

@testset "issue #9781" begin
# float(SubString) wasn't tolerant of trailing whitespace, which was different
# parse(Float64, SubString) wasn't tolerant of trailing whitespace, which was different
# to "normal" strings. This also checks we aren't being too tolerant and allowing
# any arbitrary trailing characters.
@test parse(Float64,"1\n") == 1.0
Expand Down
6 changes: 3 additions & 3 deletions test/strings/types.jl
Expand Up @@ -138,9 +138,9 @@ end
@test split(SubString("x", 2, 0), "y") == AbstractString[""]

# issue #6772
@test float(SubString("10",1,1)) === 1.0
@test float(SubString("1 0",1,1)) === 1.0
@test parse(Float32,SubString("10",1,1)) === 1.0f0
@test parse(Float64, SubString("10",1,1)) === 1.0
@test parse(Float64, SubString("1 0",1,1)) === 1.0
@test parse(Float32, SubString("10",1,1)) === 1.0f0

# issue #5870
@test !ismatch(Regex("aa"), SubString("",1,0))
Expand Down

0 comments on commit 43e18a6

Please sign in to comment.