-
-
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
Allow the conversion of AbstractUnitRanges to OrdinalRanges #40038
Conversation
Thanks for the fix. |
This is perhaps not the right fix. The conversion of an I'm not sure if the constructors Lines 1133 to 1135 in b20de6a
are the best ones? Eg. I'm not sure if julia> OrdinalRange{Int,BigInt}(1:2) |> step |> typeof
Int64 makes sense, as the step is not a |
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.
Adding a fundamental method like this might have unknown side effects. I don't know if it's suitable to backport this to 1.6 RC branch, but for this specific issue(#40035), we can get it fixed on the OffsetArray side anyway with an appropriate compat condition.
Edit:
This PR corrects the 1.6 newly added methods in #37829, so it makes sense to backport this to the 1.6-RC branch to minimize the breakage if we still have more rc releases.
@@ -1130,9 +1130,7 @@ AbstractUnitRange{T}(r::UnitRange) where {T} = UnitRange{T}(r) | |||
AbstractUnitRange{T}(r::OneTo) where {T} = OneTo{T}(r) | |||
|
|||
OrdinalRange{T1, T2}(r::StepRange) where {T1, T2<: Integer} = StepRange{T1, T2}(r) | |||
OrdinalRange{T1, T2}(r::AbstractUnitRange{T1}) where {T1, T2<:Integer} = r | |||
OrdinalRange{T1, T2}(r::UnitRange) where {T1, T2<:Integer} = UnitRange{T1}(r) | |||
OrdinalRange{T1, T2}(r::OneTo) where {T1, T2<:Integer} = OneTo{T1}(r) |
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.
I think these methods are still needed:
julia> OrdinalRange{Int, Int8}(1:10)
1:10 # master
MethodError # current PR
We might need more tests to catch this.
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.
What should this produce? I don't think that the behavior on master is correct.
julia> OrdinalRange{Int, Int8}(1:10)
1:10
julia> OrdinalRange{Int, Int8}(1:10) |> step |> typeof
Int64
However the docstring of OrdinalRange
states that OrdinalRange{T, S}
has spacings of type S
. The present behavior on master is not consistent with the docstring.
Since
julia> supertype(AbstractUnitRange)
OrdinalRange{T, T} where T
that is perhaps the conversion that makes sense.
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.
Okay, that makes sense. Given that the previous 4 methods are newly added in Julia 1.6 only(#37829), I believe it's totally fine to revert that with OrdinalRange{T, T}(r::AbstractUnitRange)
method.
Gentle bump, would be nice to have this fixed |
bd1afa9
to
04d25e5
Compare
04d25e5
to
61c1928
Compare
61c1928
to
a9c52df
Compare
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
…aLang#40038) Co-authored-by: Jameson Nash <vtjnash@gmail.com>
…aLang#40038) Co-authored-by: Jameson Nash <vtjnash@gmail.com>
Fixes #40035
Now