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

0-length index into a StepRange of TimePeriod errors #57056

Open
tiemvanderdeure opened this issue Jan 15, 2025 · 0 comments
Open

0-length index into a StepRange of TimePeriod errors #57056

tiemvanderdeure opened this issue Jan 15, 2025 · 0 comments
Labels
bug Indicates an unexpected problem or unintended behavior dates Dates, times, and the Dates stdlib module

Comments

@tiemvanderdeure
Copy link

For example:

using Dates
(Dates.Hour(1):Dates.Hour(1):Dates.Hour(2))[1:0]

Errors with

ERROR: MethodError: no method matching copysign(::Hour, ::Hour)
The function `copysign` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  copysign(::Float64, ::Float64)
   @ Base floatfuncs.jl:5
  copysign(::Float64, ::Real)
   @ Base floatfuncs.jl:8
  copysign(::Float32, ::Float32)
   @ Base floatfuncs.jl:6
  ...

Stacktrace:
 [1] getindex(r::StepRange{Hour, Hour}, s::UnitRange{Int64})
   @ Base .\range.jl:1029
 [2] top-level scope

A possible fix would be to define Base.copysign on TimePeriod. The below works

import Dates.value
Base.copysign(x::T, y::T) where T<:TimePeriod = T(copysign(value(x), value(y)))

(Dates.Hour(1):Dates.Hour(1):Dates.Hour(2))[1:0]
@nsajko nsajko added dates Dates, times, and the Dates stdlib module bug Indicates an unexpected problem or unintended behavior labels Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior dates Dates, times, and the Dates stdlib module
Projects
None yet
Development

No branches or pull requests

2 participants