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

intersect does not work with StepRange{<:AnchoredInterval} #157

Closed
sdl1 opened this issue Feb 23, 2021 · 2 comments
Closed

intersect does not work with StepRange{<:AnchoredInterval} #157

sdl1 opened this issue Feb 23, 2021 · 2 comments

Comments

@sdl1
Copy link
Member

sdl1 commented Feb 23, 2021

With StepRange{Int} it works as expected:

julia> intersect(1:1:5, 2:1:7)
2:1:5

With StepRange{<:AnchoredInterval} it does not work:

julia> dt = DateTime(2018, 1, 1);

julia> a = HE(dt):Hour(1):HE(dt + Hour(5));

julia> b = HE(dt + Hour(2)):Hour(1):HE(dt + Hour(7));

julia> intersect(a, b)
ERROR: MethodError: no method matching rem(::Millisecond, ::Hour)
Closest candidates are:
  rem(::Any, ::Any, ::RoundingMode{:ToZero}) at div.jl:67
  rem(::Any, ::Any, ::RoundingMode{:Down}) at div.jl:68
  rem(::Any, ::Any, ::RoundingMode{:Up}) at div.jl:69
  ...
Stacktrace:
 [1] intersect(::StepRange{AnchoredInterval{Hour(-1),DateTime,Open,Closed},Hour}, ::StepRange{AnchoredInterval{Hour(-1),DateTime,Open,Closed},Hour}) at ./range.jl:852
 [2] top-level scope at REPL[56]:1

The following works but returns a Vector rather than a StepRange:

julia> intersect(collect(a), b)
4-element Array{AnchoredInterval{Hour(-1),DateTime,Open,Closed},1}:
 AnchoredInterval{Hour(-1),DateTime,Open,Closed}(DateTime("2018-01-01T02:00:00"))
 AnchoredInterval{Hour(-1),DateTime,Open,Closed}(DateTime("2018-01-01T03:00:00"))
 AnchoredInterval{Hour(-1),DateTime,Open,Closed}(DateTime("2018-01-01T04:00:00"))
 AnchoredInterval{Hour(-1),DateTime,Open,Closed}(DateTime("2018-01-01T05:00:00"))

This is with julia 1.5.2 and Intervals 1.5.0

@omus
Copy link
Collaborator

omus commented Feb 24, 2021

The same issue exists with using DateTime:

julia> using Dates

julia> dt = DateTime(2018, 1, 1)
2018-01-01T00:00:00

julia> a = dt:Hour(1):dt + Hour(5);

julia> b = dt + Hour(2):Hour(1):dt + Hour(7);

julia> intersect(a,b)
ERROR: MethodError: no method matching rem(::Millisecond, ::Hour)
Closest candidates are:
  rem(::Any, ::Any, ::RoundingMode{:ToZero}) at math.jl:806
  rem(::Any, ::Any, ::RoundingMode{:Down}) at math.jl:807
  rem(::Any, ::Any, ::RoundingMode{:Up}) at math.jl:808
  ...
Stacktrace:
 [1] intersect(::StepRange{DateTime,Hour}, ::StepRange{DateTime,Hour}) at ./range.jl:807
 [2] top-level scope at REPL[7]:1

julia> intersect(collect(a), b)
4-element Array{DateTime,1}:
 2018-01-01T02:00:00
 2018-01-01T03:00:00
 2018-01-01T04:00:00
 2018-01-01T05:00:00

Note that the intersect function being called is from Base in both cases so if this issue is addressed by the Dates stdlib then this issue should also be addressed here.

Would you mind opening an issue in https://github.com/JuliaLang/julia?

@sdl1
Copy link
Member Author

sdl1 commented Feb 24, 2021

Thanks, good spot. I've opened this issue: JuliaLang/julia#39810
Closing this one.

@sdl1 sdl1 closed this as completed Feb 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants