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

BoundsError when String is indexed by an BitArray{1} #12495

Closed
diegozea opened this issue Aug 6, 2015 · 4 comments
Closed

BoundsError when String is indexed by an BitArray{1} #12495

diegozea opened this issue Aug 6, 2015 · 4 comments
Labels
domain:strings "Strings!"

Comments

@diegozea
Copy link
Contributor

diegozea commented Aug 6, 2015

I found this BoundsError trying to index an ASCIIString using a BitArray{1}:

julia> a = "ABC"
"ABC"

julia> b = [1,2,3].!=2
3-element BitArray{1}:
  true
 false
  true

julia> a[b]
ERROR: BoundsError: attempt to access 3-element Array{UInt8,1}:
 0x41
 0x42
 0x43
  at index [0]
 in anonymous at strings/basic.jl:43
 in sprint at ./iostream.jl:206
 in getindex at strings/basic.jl:42

julia> @which a[b]
getindex(s::AbstractString, v::AbstractArray{T,1}) at strings/basic.jl:42

...but using a Vector{Bool} is fine:

julia> a[[true, false, true]]
"AC"

julia> @which a[[true, false, true]]
getindex(s::ASCIIString, r::Array{T,1}) at ascii.jl:19
@StefanKarpinski
Copy link
Sponsor Member

Hmm. I'm not sure if logical indexing of strings is a good idea. Although it can actually be done efficiently.

@ivarne
Copy link
Sponsor Member

ivarne commented Aug 6, 2015

Ref #4763, where the same issue was raised for SubArray

@kshyatt kshyatt added the domain:strings "Strings!" label Jan 25, 2017
@kshyatt
Copy link
Contributor

kshyatt commented Jan 25, 2017

Still happens on master.

@KristofferC KristofferC changed the title BoundsError when ASCIIString is indexed by an BitArray{1} BoundsError when String is indexed by an BitArray{1} Jan 26, 2017
@nalimilan
Copy link
Member

Actually, no: now a[[true, false, true]] gives the same error, which at least is consistent. I'm not persuaded we need logical indexing of strings either, so what we could do is restrict the signature of getindex to ::AbstractVector{<:Integer} to make it a MethodError.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:strings "Strings!"
Projects
None yet
Development

No branches or pull requests

5 participants