# TimeArray and last don't play well together

**URL:** <https://discourse.julialang.org/t/timearray-and-last-dont-play-well-together/74296>\
**Category:** General Usage\
**Tags:** time-series\
**Created:** [January 9, 2022, 6:28pm UTC](https://discourse.julialang.org/t/timearray-and-last-dont-play-well-together/74296 "2022-01-09T18:28:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![JackStrauss](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@JackStrauss](https://discourse.julialang.org/u/JackStrauss)\
**Post date:** [January 9, 2022, 6:28pm UTC](https://discourse.julialang.org/t/timearray-and-last-dont-play-well-together/74296/1 "2022-01-09T18:28:33Z")

</div>

Hi all

I am puzzled as to why TimeArray does not fully work with last()

```julia
using Dates, TimeSeries
dates = Date(2018, 1, 1):Day(1):Date(2018, 12, 31)
ta = TimeArray(dates, rand(length(dates)))

```

then last(ta) works but last(ta,10) fails

all the best, Jack

---

<div class="post-metadata">

**Author:** ![TheCedarPrince](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thecedarprince/32/17323_2.png) [@TheCedarPrince](https://discourse.julialang.org/u/TheCedarPrince)\
**Post date:** [January 9, 2022, 6:45pm UTC](https://discourse.julialang.org/t/timearray-and-last-dont-play-well-together/74296/2 "2022-01-09T18:45:33Z")

</div>

Hi @JackStrauss !

Just some clarification questions:

Could you pass the error you get and also what you are expecting it should do @JackStrauss ?  
Thanks!

~ tcp 🌳

---

<div class="post-metadata">

**Author:** ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)\
**Post date:** [January 9, 2022, 6:49pm UTC](https://discourse.julialang.org/t/timearray-and-last-dont-play-well-together/74296/3 "2022-01-09T18:49:47Z")

</div>

```julia
julia> last(ta, 1)
ERROR: MethodError: no method matching iterate(::Base.Iterators.Reverse{TimeArray{Float64, 1, Date, Vector{Float64}}})

```

I would file an issue on TimeSeries.jl

---

<div class="post-metadata">

**Author:** ![JackStrauss](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@JackStrauss](https://discourse.julialang.org/u/JackStrauss)\
**Post date:** [January 9, 2022, 7:40pm UTC](https://discourse.julialang.org/t/timearray-and-last-dont-play-well-together/74296/4 "2022-01-09T19:40:55Z")

</div>

[jzr](https://discourse.julialang.org/u/jzr)  
So you recon its a bug. I’ll file it with TimeSeries then.

---

<div class="post-metadata">

**Author:** ![rocco\_sprmnt21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rocco_sprmnt21/32/20127_2.png) [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Post date:** [January 9, 2022, 8:58pm UTC](https://discourse.julialang.org/t/timearray-and-last-dont-play-well-together/74296/5 "2022-01-09T20:58:29Z")

</div>

try

```julia
ta[end-9:end]
#or 
tail(ta,10)

```

if you need first n

```julia
head(ta,n)

```

---

<div class="post-metadata">

**Author:** ![JackStrauss](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@JackStrauss](https://discourse.julialang.org/u/JackStrauss)\
**Post date:** [January 9, 2022, 9:10pm UTC](https://discourse.julialang.org/t/timearray-and-last-dont-play-well-together/74296/6 "2022-01-09T21:10:01Z")

</div>

Thanks [rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)

Indeed, thats what I ended up doing, its just that I was puzzled by the failure of last(ta,1) and wondering if it was some Julia idiosyncrasy that I had missed.
