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

recur fails when the DateFunction provided returns false outside of the range #17513

Closed
spurll opened this issue Jul 20, 2016 · 1 comment · Fixed by #19288
Closed

recur fails when the DateFunction provided returns false outside of the range #17513

spurll opened this issue Jul 20, 2016 · 1 comment · Fixed by #19288
Labels
dates Dates, times, and the Dates stdlib module

Comments

@spurll
Copy link
Contributor

spurll commented Jul 20, 2016

The way recur is currently written requires that it be able to find at least one case where the DateFunction returns true once it steps outside of the StepRange provided. For this reason, even though these two examples should produce identical results, the second one throws an error:

julia> Dates.recur(Date(1980):Dates.Day(-1):Date(1970)) do d
           Dates.ismonday(d) && d >= Date(1969)
       end
522-element Array{Date,1}:
 1979-12-31
 1979-12-24
 1979-12-17
          
 1970-01-19
 1970-01-12
 1970-01-05

julia> Dates.recur(Date(1980):Dates.Day(-1):Date(1970)) do d
           Dates.ismonday(d) && d >= Date(1970)
       end
ERROR: ArgumentError: Adjustment limit reached: 10000 iterations
 in adjust(::Base.Dates.DateFunction, ::Date, ::Base.Dates.Day, ::Int64) at ./dates/adjusters.jl:148
 in #recur#24(::Base.Dates.Day, ::Bool, ::Int64, ::Function, ::Function, ::Date, ::Date) at ./dates/adjusters.jl:282
 in (::Base.Dates.#kw##recur)(::Array{Any,1}, ::Base.Dates.#recur, ::Function, ::Date, ::Date) at ./<missing>:0
 in recur(::Function, ::StepRange{Date,Base.Dates.Day}) at ./dates/adjusters.jl:299
 in eval(::Module, ::Any) at ./boot.jl:234
 in macro expansion at ./REPL.jl:92 [inlined]
 in (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at ./event.jl:46

This happens because adjust is called again even when cmp(next, stop) returns 0. If that call fails (because the DateFunction doesn't return true within limit attempts) then an error results, even though we're already done filling our array of results.

Of course, here the bug could be avoided by simply removing the second check from the DateFunction. The case in which I encountered this problem is a little more complex, but I think the point is adequately demonstrated by this example.

I'm running a random recent build (0.5.0-dev+5275; sorry!) but I've verified that this is present on 0.4.5 as well. Here's my current version information:

julia> versioninfo()
Julia Version 0.5.0-dev+5275
Commit 45400d0 (2016-07-11 13:46 UTC)
Platform Info:
  System: Darwin (x86_64-apple-darwin15.5.0)
  CPU: Intel(R) Core(TM) i7-4558U CPU @ 2.80GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.7.1 (ORCJIT, haswell)
@tkelman tkelman added the dates Dates, times, and the Dates stdlib module label Jul 20, 2016
@simonbyrne
Copy link
Contributor

I've now removed Dates.recur, since it is essentially equivalent to Base.filter (which doesn't have the problem outlined above).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dates Dates, times, and the Dates stdlib module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants