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

Deprecate float(::String) #24220

Merged
merged 1 commit into from
Oct 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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