-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Add a contract for Ordered
and additional traits
#37239
base: master
Are you sure you want to change the base?
Conversation
If we agree to the proposed changes I will add tests. Also a decision is if something should be exported from Base (e.g. |
CC @nalimilan |
Let's hear what @timholy says. Maybe we could make it more explicit whether the trait is optional (e.g. enables optimizations) or whether it should be implemented by types that implement If the idea is right, I would even go as far as defining the trait for all types that match it, even if they are "rare". For |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a good idea. It's scary to have people ask you what you actually mean, though.
CI fails as some types are undefined at this stage. I will fix this and add tests once we get back more feedback on the proposal. |
Co-authored-by: Tim Holy <tim.holy@gmail.com>
@timholy - CI fails but I think it is a bug in Here is a MWE (tested on 1.6.0-DEV.584 (2020-08-05)):
this is fixed by adding:
definition (note |
Having thought about it more maybe it is OK to require defining |
Also related is #37255 |
Re. the ambiguity, due to julia> Union{Type{Union{}}, Type{Missing}} == Type{<:Missing}
false it is not sufficient to define methods for |
Agreed - I was confused by the fact that you actually do not have a situation when |
@bkamins you're right, but we haven't bother to teach the ambiguity checker about that sort of method tiling possibility since it hasn't come up before |
Sure - I think what is now is OK after thinking about it and I just added |
Co-authored-by: Milan Bouchet-Valat <nalimilan@club.fr>
Is there any recommendation where tests of this should be put? |
@nalimilan - are we OK with this proposal? If yes, then I will add tests somewhere and finalize this PR (if you have a recommendation where to put the tests please let me know). |
Just to ask, does I only ask because OrderedCollections.jl (and by extension, DataStructures.jl) distinguish between “ordered” and “sorted”, and it would be nice to be consistent. |
Ah, never mind--glancing at the PR, I understand now that this refers to something different. |
@kmsquire "Ordered" here more or less means "sortable". The latter would probably be more in line with the OrderedCollections terminology I guess. Feel free to file an issue to discuss renaming this (I don't think it's used a lot currently as it's not even documented). The name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nalimilan - are we OK with this proposal? If yes, then I will add tests somewhere and finalize this PR (if you have a recommendation where to put the tests please let me know).
Looks OK, I've made a proposal regarding the wording. No idea where to put tests.
Co-authored-by: Milan Bouchet-Valat <nalimilan@club.fr>
Thank you. I have added the tests to sorting.jl |
This would be very useful to have for packages like DimensionalData.jll. Currently we need to use Are there any blockers to merging this? |
@rafaqz - someone probably needs to take the "ownership" of this functionality. I did not push for it as it was not resolved quickly, so I had to use In summary - I can finalize this PR if we want it, but I would suggest that it is clear who later tracks its consequences in the ecosystem. |
I guess it's probably you and me who need this the most, but I also have very limited time to make sure it's implemented widely enough to be a useful replacement for |
That was my thinking. I.e. in DataFrames.jl I needed to fall back to |
Based on the discussions with @nalimilan this PR proposes:
Ordered
trait so that external packages can also use itOrdered
trait to relevant exported types that defineisless
methods in a safe wayFrom this PR I have excluded the following types defined in standard Julia installation:
AbstractArray
Tuple
NamedTuple
Pair
Ptr
VersionNumber
Base.CoreLogging.LogLevel
Base.Enums.Enum
Base.SHA1
Base.Unicode.GraphemeIterator
Base.UUID
Pkg.Resolve.FieldValue
Pkg.Resolve.VersionWeight
Sockets.IPAddr
as I thought that either very rare or do not meet the contract I proposed (like
AbstractArray
)