xKDR / TSFrames.jl

Timeseries in Julia
MIT License
91 stars 22 forks source link

`MethodError` with `issorted = True` #152

Open smishr opened 1 year ago

smishr commented 1 year ago

I ran the following code in a Pluto notebook

using TSFrames, MarketData
sp500 = TSFrame(MarketData.yahoo("^GSPC"), issorted = true)

This raises error:

MethodError: no method matching TSFrames.TSFrame(::TimeSeries.TimeArray{Float64, 2, Dates.Date, Matrix{Float64}}; issorted=true)

Closest candidates are:

TSFrames.TSFrame(::Any) at ~/.julia/packages/TSFrames/IrHRj/src/TSFrame.jl:352 got unsupported keyword argument "issorted"

TSFrames.TSFrame(!Matched::AbstractMatrix{T}; colnames) where T at ~/.julia/packages/TSFrames/IrHRj/src/TSFrame.jl:385 got unsupported keyword argument "issorted"

TSFrames.TSFrame(!Matched::AbstractMatrix{T}, !Matched::AbstractVector{V}; colnames) where {T, V} at ~/.julia/packages/TSFrames/IrHRj/src/TSFrame.jl:391 got unsupported keyword argument "issorted"
...

I then tried without issorted, which works perfectly fine:

sp500 = TSFrame(MarketData.yahoo("^GSPC"))
chiraganand commented 1 year ago

This must be happening because conversion from TimeArray to TSFrame is done by the Tables.jl interfaces. We'll have to check if this can be fixed by modifying the constructor, not sure if we can modify the Tables.jl interfaces which might break compatibility. @codetalker7 @asinghvi17 What do you guys think?

codetalker7 commented 1 year ago

@smishr @chiraganand the given code is working for me just fine:

julia> using TSFrames, MarketData;
julia> sp500 = TSFrame(MarketData.yahoo("^GSPC"), issorted = true)
13136×6 TSFrame with Date Index
 Index       Open     High     Low      Close    AdjClose  Volume    
 Date        Float64  Float64  Float64  Float64  Float64   Float64   
─────────────────────────────────────────────────────────────────────
 1971-02-08     0.0     98.04    96.13    97.45     97.45  2.559e7
 1971-02-09     0.0     98.5     96.9     97.51     97.51  2.825e7
 1971-02-10     0.0     97.97    96.23    97.39     97.39  1.904e7
 1971-02-11     0.0     98.49    96.99    97.91     97.91  1.926e7
 1971-02-12     0.0     98.96    97.56    98.43     98.43  1.847e7
 1971-02-16     0.0     99.59    97.85    98.66     98.66  2.135e7
 1971-02-17     0.0     99.32    97.32    98.2      98.2   1.872e7
 1971-02-18     0.0     98.6     96.96    97.56     97.56  1.665e7
 1971-02-19     0.0     97.79    96.25    96.74     96.74  1.786e7
 1971-02-22     0.0     96.65    94.97    95.72     95.72  1.584e7
 1971-02-23     0.0     96.67    94.92    96.09     96.09  1.508e7
 1971-02-24     0.0     97.34    95.86    96.73     96.73  1.593e7
 1971-02-25     0.0     97.71    96.08    96.96     96.96  1.62e7
 1971-02-26     0.0     97.54    95.84    96.75     96.75  1.725e7
     ⋮          ⋮        ⋮        ⋮        ⋮        ⋮          ⋮
 2023-02-17  4077.39  4081.51  4047.95  4079.09   4079.09  4.04548e9
 2023-02-21  4052.35  4052.35  3995.19  3997.34   3997.34  4.12159e9
 2023-02-22  4001.83  4017.37  3976.9   3991.05   3991.05  4.07932e9
 2023-02-23  4018.6   4028.3   3969.19  4012.32   4012.32  3.95294e9
 2023-02-24  3973.24  3978.25  3943.08  3970.04   3970.04  3.8777e9
 2023-02-27  3992.36  4018.05  3973.55  3982.24   3982.24  3.83695e9
 2023-02-28  3977.19  3997.5   3968.98  3970.15   3970.15  5.0434e9
 2023-03-01  3963.34  3971.73  3939.05  3951.39   3951.39  4.24948e9
 2023-03-02  3938.68  3990.84  3928.16  3981.35   3981.35  4.2449e9
 2023-03-03  3998.02  4048.29  3995.17  4045.64   4045.64  4.08473e9
 2023-03-06  4055.15  4078.49  4044.61  4048.42   4048.42  4.00087e9
 2023-03-07  4048.26  4050.0   3980.31  3986.37   3986.37  3.9225e9
 2023-03-08  3987.55  4000.41  3969.76  3992.01   3992.01  3.53557e9
 2023-03-09  3998.66  4017.81  3908.7   3918.32   3918.32  4.44526e9
                                                   13108 rows omitted

@smishr could it be that you have checked out some old version of TSFrames? Just for reference, v0.2.0 doesn't have support for the issorted kwarg.

codetalker7 commented 1 year ago

On a side note, @chiraganand I just noticed: the documentation for TSFrames.TSFrame doesn't have any mention of the Tables.jl constructor. I think we should add it.

asinghvi17 commented 1 year ago

I can't reproduce this locally either. Given that none of the proposed method signatures in the error message have the issorted keyword, I'm pretty sure you're using a version before the issorted PR was merged.

smishr commented 1 year ago

Thanks, ill troubleshoot with your suggestions and give more details if error is still encountered.

smishr commented 1 year ago

I resolved the issue. Pluto hardcodes the version of each package with the notebook. In my case it was hardcoded to v0.2.0, not 0.2.1.