-
-
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
Tweaks to StepRange: Take 2 #6700
Conversation
Bump. Thoughts on this? Too hackish? I'd really like to have this for 0.3 release. |
@@ -54,6 +54,8 @@ immutable StepRange{T,S} <: OrdinalRange{T,S} | |||
end | |||
end | |||
|
|||
steprem(start,stop,step) = (stop-start) % step |
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.
Why not just override %
?
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.
Nevermind. I just looked a little closer at your implementation in Dates.
I don't understand the implementation of |
Drat, somehow my updated version got lost in some branch shuffling. I just pushed the version that works. Base.steprem(a::Date,b::Date,c::Day) = (b-a) % c
Base.steprem(a::DateTime,b::DateTime,c::Millisecond) = (b-a) % c
function Base.steprem(start::TimeType,stop::TimeType,step::Period)
start,stop = start > stop ? (stop,start) : (start,stop)
step = step < zero(step) ? -step : step
t = start
while (t+step) <= stop
t += step
end
return stop - t
end |
I thought about having that manual definition of |
Ok, I've updated the Dates.jl range code and added a bunch more tests (based on this patch). Feel free to take a look and let me know if this is good to go or if we should try something else. Dates.jl range code: https://github.com/karbarcca/Dates.jl/blob/master/src/ranges.jl |
Ok, added another round of testing/tweaks to the range code in |
Ok, updated the |
Tweaks to StepRange: Take 2
The
issorted
andin
changes are pretty straightforward, using the step for comparison.sort
andsortperm
remove theT<:Real
restriction to apply toStepRange
as well. Alltest/ranges.jl
tests still pass with these changes, though I can add some more and try to break things if needed.The introduction of
steprem
is annoying, but surprisingly minimal to allow full support for different step types than the difference between start and stop. The reasoning is that most Ordinal types shouldn't have to worry because the fallback to(stop-start) % step
should work, but it allows for overloading (similar to how I'm overloadinglength
).Fixes #6638
cc: @JeffBezanson
Support methods I'm using to get range functionality for dates: https://github.com/karbarcca/Dates.jl/blob/master/src/ranges.jl
Relevant tests the date ranges are passing with these changes: https://github.com/karbarcca/Dates.jl/blob/master/test/test_ranges.jl