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

Search and find* deprecations fixes and improvements #26149

Merged
merged 3 commits into from
Mar 7, 2018
Merged

Conversation

nalimilan
Copy link
Member

@nalimilan nalimilan commented Feb 21, 2018

See commit messages.

Fixes #26145.

@mbauman
Copy link
Sponsor Member

mbauman commented Feb 21, 2018

Looks like we're also missing this deprecation:

julia> search(UInt8[1,2,3],UInt8[1,2])
ERROR: MethodError: no method matching search(::Array{UInt8,1}, ::Array{UInt8,1})
Closest candidates are:
  search(::Union{Array{Int8,1}, Array{UInt8,1}}, ::Union{Int8, UInt8}) at deprecated.jl:55
  search(::Union{Array{Int8,1}, Array{UInt8,1}}, ::Union{Int8, UInt8}, ::Integer) at deprecated.jl:55
  search(::Union{Array{Int8,1}, Array{UInt8,1}}, ::Char) at deprecated.jl:55
  …

@nalimilan
Copy link
Member Author

We don't support looking for a sequence of elements in a collection (except for the special case of strings). Vector{UInt8} was the only supported type, mostly because of how string search was implemented, and it wasn't documented. If you're interested in this, it would be worth discussing possible designs, e.g. findfirst(sequence(needle), haystack), or just findfirst(needle, haystack) (which could be confusing since you could expect it to be equivalent to findfirst(occursin(needle), haystack)).

@mbauman
Copy link
Sponsor Member

mbauman commented Feb 21, 2018

Ah, ok. I was just reviewing the PR based upon what the diff showed and the behaviors of 0.6 and 0.7 — we have deprecations for rsearch(::ByteArray, ::ByteArray) but not search. Not trying to re-design a whole thing.

@mbauman mbauman added kind:deprecation This change introduces or involves a deprecation domain:search & find The find* family of functions labels Feb 21, 2018
@nalimilan
Copy link
Member Author

Ah, indeed. That's just an oversight, I didn't think about it when implementing deprecations for all existing methods. They don't give correct results since they consider the array as an element rather than as a sequence. I've added a commit to remove them.

@nalimilan
Copy link
Member Author

While I'm at it, I've added a commit to return nothing rather than an empty range, as discussed on #triage last week.

@nalimilan nalimilan changed the title Fix search and find* deprecations to return 0 instead of nothing Search and find* deprecations fixes and improvements Feb 21, 2018
@garrison
Copy link
Sponsor Member

garrison commented Feb 23, 2018

I'm not sure how I feel about this final commit which returns nothing rather than the empty range. What is the reasoning? It seems to me like it will mean one must always test for nothing explicitly, and if a person forgets, it will lead to rare unhandled exceptions.

EDIT: Stefan convinced me; I agree that this makes sense.

@StefanKarpinski
Copy link
Sponsor Member

The reasoning is that there are patterns (e.g. regular expressions) which can match an empty range, so returning an empty range to indicate "no match" is a poor generic API.

@JeffBezanson JeffBezanson added this to the 1.0 milestone Mar 6, 2018
The current behavior breaks backward compatibility.
We do not provide any replacement for these methods which have never been documented.
…or no match

This is more consistent with functions which return a single index. It also allows
distinguishing no match from an empty match.
@nalimilan nalimilan merged commit fa462ba into master Mar 7, 2018
@nalimilan nalimilan deleted the nl/searchdepr branch March 7, 2018 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:search & find The find* family of functions kind:deprecation This change introduces or involves a deprecation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants