From b560483d1c43386feb8d11fe20f5f51ec1ce9e1d Mon Sep 17 00:00:00 2001 From: Rodrigo Chang Date: Wed, 17 Mar 2021 10:16:25 -0600 Subject: [PATCH 1/6] modified show, added omitted columns --- src/timearray.jl | 127 +++++++++++++++++++++++++++++------------------ 1 file changed, 79 insertions(+), 48 deletions(-) diff --git a/src/timearray.jl b/src/timearray.jl index 73ff77c1..82e7d0a7 100644 --- a/src/timearray.jl +++ b/src/timearray.jl @@ -202,14 +202,14 @@ calculate the paging """ @inline function _showpages(dcol::Int, timewidth::Int, colwidth::Array{Int}) ret = UnitRange{Int}[] - c = dcol - timewidth - 4 + c = dcol - timewidth - 5 last_i = 1 for i in eachindex(colwidth) w = colwidth[i] + 3 if c - w < 0 push!(ret, last_i:i-1) # next page - c = dcol - timewidth - 4 - w + c = dcol - timewidth - 5 - w last_i = i elseif i == length(colwidth) push!(ret, last_i:i) @@ -237,7 +237,7 @@ function print_time_array(io::IO, ta::TimeArray{T}, short=false) where T # calculate column withs drow, dcol = displaysize(io) - res_row = 7 # number of reserved rows: summary line, lable line ... etc + res_row = 9 # number of reserved rows: summary line, label line ... etc half_row = floor(Int, (drow - res_row) / 2) add_row = (drow - res_row) % 2 @@ -247,6 +247,8 @@ function print_time_array(io::IO, ta::TimeArray{T}, short=false) where T strs = _showval.(@view values(ta)[[tophalf; bothalf], :]) ts = @view timestamp(ta)[[tophalf; bothalf]] else + tophalf = 0 + bothalf = 0 strs = _showval.(values(ta)) ts = timestamp(ta) end @@ -259,60 +261,89 @@ function print_time_array(io::IO, ta::TimeArray{T}, short=false) where T spacetime = textwidth(string(ts[1])) pages = _showpages(dcol, spacetime, colwidth) - for p ∈ pages - # row label line - ## e.g. | Open | High | Low | Close | - print(io, "│", " "^(spacetime + 2)) - for (name, w) in zip(colnames(ta)[p], colwidth[p]) - print(io, "│ ", _rpad(name, w + 1)) - end - println(io, "│") - ## e.g. ├───────┼───────┼───────┼────────┤ - print(io, "├", "─"^(spacetime + 2)) - for w in colwidth[p] - print(io, "┼", "─"^(w + 2)) - end - print(io, "┤") - - # timestamp and values line - if nrow > (drow - res_row) - for i in tophalf - println(io) - print(io, "│ ", ts[i], " ") - for j in p - print(io, "│ ", _rpad(strs[i, j], colwidth[j] + 1)) - end - print(io, "│") - end + _print_page(io, pages[1], ta, + spacetime, colwidth, nrow, drow, res_row, tophalf, bothalf, + length(pages)) + + if length(pages) > 1 + pndtcols = last(last(pages)) - first(pages[2]) + 1 + print(io, "\n ", pndtcols, " columns omitted") + end +end - print(io, "\n \u22EE") +""" + _print_page - for i in (length(bothalf) - 1):-1:0 - i = size(strs, 1) - i - println(io) - print(io, "│ ", ts[i], " ") - for j in p - print(io, "│ ", _rpad(strs[i, j], colwidth[j] + 1)) - end - print(io, "│") +Helper function to print a single page of the `TimeArray` +""" +function _print_page(io::IO, p::UnitRange{Int}, ta::TimeArray, spacetime, + colwidth, nrow, drow, res_row, tophalf, bothalf, pages) + + strs = _showval.(values(ta)) + ts = timestamp(ta) + last = pages > 1 ? "│\u22EF" : "│" + + # row label line + ## e.g. | Open | High | Low | Close | + print(io, "│", " "^(spacetime + 2)) + for (name, w) in zip(colnames(ta)[p], colwidth[p]) + print(io, "│ ", _rpad(name, w + 1)) + end + println(io, last) + + ## e.g. ├───────┼───────┼───────┼────────┤ + print(io, "├", "─"^(spacetime + 2)) + for w in colwidth[p] + print(io, "┼", "─"^(w + 2)) + end + print(io, "┤") + + # timestamp and values line + if nrow > (drow - res_row) + + # print bottom part + for i in tophalf + println(io) + print(io, "│ ", ts[i], " ") + for j in p + print(io, "│ ", _rpad(strs[i, j], colwidth[j] + 1)) end + print(io, i % 3 == 0 ? last : "│") + end - else - for i in 1:nrow - println(io) - print(io, "│ ", ts[i], " ") - for j in p - print(io, "│ ", _rpad(strs[i, j], colwidth[j] + 1)) - end - print(io, "│") + # print vdots part + println(io) + print(io, "│ ", _rpad("\u22EE", spacetime + 1)) + for j in p + print(io, "│ ", _rpad("\u22EE", colwidth[j] + 1)) + end + # print(io, pages > 1 ? "│\u22F1" : "│") + print(io, "│") + + # print bottom part + for i in (length(bothalf) - 1):-1:0 + i = size(strs, 1) - i + println(io) + print(io, "│ ", ts[i], " ") + for j in p + print(io, "│ ", _rpad(strs[i, j], colwidth[j] + 1)) end + print(io, i % 3 == 0 ? last : "│") end - if length(pages) > 1 && p != pages[end] - print(io, "\n\n") + else + # print all rows + for i in 1:nrow + println(io) + print(io, "│ ", ts[i], " ") + for j in p + print(io, "│ ", _rpad(strs[i, j], colwidth[j] + 1)) + end + print(io, i % 3 == 0 ? last : "│") end - end # for p ∈ pages + end end + Base.show(io::IO, ta::TimeArray) = print_time_array(io, ta, true) Base.show(io::IO, ::MIME"text/plain", ta::TimeArray) = print_time_array(io, ta, false) From 143345188da064266b0601d3c9b776c2e9a15927 Mon Sep 17 00:00:00 2001 From: Rodrigo Chang Date: Thu, 18 Mar 2021 09:44:38 -0600 Subject: [PATCH 2/6] Colored message in right hand side for omitted columns (#468) with tests added --- src/timearray.jl | 3 ++- test/timearray.jl | 44 +++++++++----------------------------------- 2 files changed, 11 insertions(+), 36 deletions(-) diff --git a/src/timearray.jl b/src/timearray.jl index 82e7d0a7..3747a3ab 100644 --- a/src/timearray.jl +++ b/src/timearray.jl @@ -267,7 +267,8 @@ function print_time_array(io::IO, ta::TimeArray{T}, short=false) where T if length(pages) > 1 pndtcols = last(last(pages)) - first(pages[2]) + 1 - print(io, "\n ", pndtcols, " columns omitted") + println(io) + printstyled(io, lpad("$pndtcols columns omitted", dcol), color=:cyan) end end diff --git a/test/timearray.jl b/test/timearray.jl index acfb43cb..4c71bf3d 100644 --- a/test/timearray.jl +++ b/test/timearray.jl @@ -497,9 +497,7 @@ end │ 2000-01-10 │ 97.75 │ │ 2000-01-11 │ 92.75 │ │ 2000-01-12 │ 87.19 │ -│ 2000-01-13 │ 96.75 │ - ⋮ -│ 2001-12-19 │ 21.62 │ +│ ⋮ │ ⋮ │ │ 2001-12-20 │ 20.67 │ │ 2001-12-21 │ 21.0 │ │ 2001-12-24 │ 21.36 │ @@ -528,9 +526,7 @@ end │ 2000-01-10 │ 102.0 │ 102.25 │ 94.75 │ 97.75 │ │ 2000-01-11 │ 95.94 │ 99.38 │ 90.5 │ 92.75 │ │ 2000-01-12 │ 95.0 │ 95.5 │ 86.5 │ 87.19 │ -│ 2000-01-13 │ 94.48 │ 98.75 │ 92.5 │ 96.75 │ - ⋮ -│ 2001-12-19 │ 20.58 │ 21.68 │ 20.47 │ 21.62 │ +│ ⋮ │ ⋮ │ ⋮ │ ⋮ │ ⋮ │ │ 2001-12-20 │ 21.4 │ 21.47 │ 20.62 │ 20.67 │ │ 2001-12-21 │ 21.01 │ 21.54 │ 20.8 │ 21.0 │ │ 2001-12-24 │ 20.9 │ 21.45 │ 20.9 │ 21.36 │ @@ -548,47 +544,25 @@ end show(io, "text/plain", AAPL) let str = String(take!(io)) out = """8336×12 TimeArray{Float64,2,Date,Array{Float64,2}} 1980-12-12 to 2013-12-31 -│ │ Open │ High │ Low │ Close │ Volume │ ExDividend │ +│ │ Open │ High │ Low │ Close │ Volume │ ExDividend │⋯ ├────────────┼────────┼────────┼────────┼────────┼───────────┼────────────┤ │ 1980-12-12 │ 28.75 │ 28.88 │ 28.75 │ 28.75 │ 2.0939e6 │ 0.0 │ │ 1980-12-15 │ 27.38 │ 27.38 │ 27.25 │ 27.25 │ 785200.0 │ 0.0 │ -│ 1980-12-16 │ 25.38 │ 25.38 │ 25.25 │ 25.25 │ 472000.0 │ 0.0 │ +│ 1980-12-16 │ 25.38 │ 25.38 │ 25.25 │ 25.25 │ 472000.0 │ 0.0 │⋯ │ 1980-12-17 │ 25.88 │ 26.0 │ 25.88 │ 25.88 │ 385900.0 │ 0.0 │ │ 1980-12-18 │ 26.62 │ 26.75 │ 26.62 │ 26.62 │ 327900.0 │ 0.0 │ -│ 1980-12-19 │ 28.25 │ 28.38 │ 28.25 │ 28.25 │ 217100.0 │ 0.0 │ +│ 1980-12-19 │ 28.25 │ 28.38 │ 28.25 │ 28.25 │ 217100.0 │ 0.0 │⋯ │ 1980-12-22 │ 29.62 │ 29.75 │ 29.62 │ 29.62 │ 166800.0 │ 0.0 │ │ 1980-12-23 │ 30.88 │ 31.0 │ 30.88 │ 30.88 │ 209600.0 │ 0.0 │ -│ 1980-12-24 │ 32.5 │ 32.62 │ 32.5 │ 32.5 │ 214300.0 │ 0.0 │ - ⋮ -│ 2013-12-19 │ 549.5 │ 550.0 │ 543.73 │ 544.46 │ 1.14396e7 │ 0.0 │ +│ ⋮ │ ⋮ │ ⋮ │ ⋮ │ ⋮ │ ⋮ │ ⋮ │ │ 2013-12-20 │ 545.43 │ 551.61 │ 544.82 │ 549.02 │ 1.55862e7 │ 0.0 │ -│ 2013-12-23 │ 568.0 │ 570.72 │ 562.76 │ 570.09 │ 1.79038e7 │ 0.0 │ +│ 2013-12-23 │ 568.0 │ 570.72 │ 562.76 │ 570.09 │ 1.79038e7 │ 0.0 │⋯ │ 2013-12-24 │ 569.89 │ 571.88 │ 566.03 │ 567.67 │ 5.9841e6 │ 0.0 │ │ 2013-12-26 │ 568.1 │ 569.5 │ 563.38 │ 563.9 │ 7.286e6 │ 0.0 │ -│ 2013-12-27 │ 563.82 │ 564.41 │ 559.5 │ 560.09 │ 8.0673e6 │ 0.0 │ +│ 2013-12-27 │ 563.82 │ 564.41 │ 559.5 │ 560.09 │ 8.0673e6 │ 0.0 │⋯ │ 2013-12-30 │ 557.46 │ 560.09 │ 552.32 │ 554.52 │ 9.0582e6 │ 0.0 │ │ 2013-12-31 │ 554.17 │ 561.28 │ 554.0 │ 561.02 │ 7.9673e6 │ 0.0 │ - -│ │ SplitRatio │ AdjOpen │ AdjHigh │ AdjLow │ AdjClose │ -├────────────┼────────────┼──────────┼──────────┼──────────┼──────────┤ -│ 1980-12-12 │ 1.0 │ 3.3766 │ 3.3919 │ 3.3766 │ 3.3766 │ -│ 1980-12-15 │ 1.0 │ 3.2157 │ 3.2157 │ 3.2004 │ 3.2004 │ -│ 1980-12-16 │ 1.0 │ 2.9808 │ 2.9808 │ 2.9655 │ 2.9655 │ -│ 1980-12-17 │ 1.0 │ 3.0395 │ 3.0536 │ 3.0395 │ 3.0395 │ -│ 1980-12-18 │ 1.0 │ 3.1264 │ 3.1417 │ 3.1264 │ 3.1264 │ -│ 1980-12-19 │ 1.0 │ 3.3179 │ 3.3331 │ 3.3179 │ 3.3179 │ -│ 1980-12-22 │ 1.0 │ 3.4788 │ 3.494 │ 3.4788 │ 3.4788 │ -│ 1980-12-23 │ 1.0 │ 3.6267 │ 3.6408 │ 3.6267 │ 3.6267 │ -│ 1980-12-24 │ 1.0 │ 3.817 │ 3.8311 │ 3.817 │ 3.817 │ - ⋮ -│ 2013-12-19 │ 1.0 │ 546.2492 │ 546.7463 │ 540.5133 │ 541.239 │ -│ 2013-12-20 │ 1.0 │ 542.2033 │ 548.3467 │ 541.5969 │ 545.7721 │ -│ 2013-12-23 │ 1.0 │ 564.6398 │ 567.3437 │ 559.4308 │ 566.7174 │ -│ 2013-12-24 │ 1.0 │ 566.5186 │ 568.4968 │ 562.6814 │ 564.3117 │ -│ 2013-12-26 │ 1.0 │ 564.7392 │ 566.1309 │ 560.0471 │ 560.564 │ -│ 2013-12-27 │ 1.0 │ 560.4845 │ 561.071 │ 556.1901 │ 556.7766 │ -│ 2013-12-30 │ 1.0 │ 554.1621 │ 556.7766 │ 549.0525 │ 551.2395 │ -│ 2013-12-31 │ 1.0 │ 550.8916 │ 557.9595 │ 550.7226 │ 557.7011 │""" + 5 columns omitted""" @test str == out end From 0a494fec42b84eea2f7f1e73c10cde2da7812905 Mon Sep 17 00:00:00 2001 From: Rodrigo Chang Date: Tue, 23 Mar 2021 09:22:13 -0600 Subject: [PATCH 3/6] Added @show support to print all columns (#468) --- src/timearray.jl | 40 +++++++++++++++++++-------- test/timearray.jl | 69 +++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 87 insertions(+), 22 deletions(-) diff --git a/src/timearray.jl b/src/timearray.jl index 3747a3ab..f17fc07c 100644 --- a/src/timearray.jl +++ b/src/timearray.jl @@ -220,7 +220,7 @@ calculate the paging ret end -function print_time_array(io::IO, ta::TimeArray{T}, short=false) where T +function print_time_array(io::IO, ta::TimeArray{T}, short=false, allcols=false) where T # summary line nrow = size(values(ta), 1) ncol = size(values(ta), 2) @@ -261,14 +261,29 @@ function print_time_array(io::IO, ta::TimeArray{T}, short=false) where T spacetime = textwidth(string(ts[1])) pages = _showpages(dcol, spacetime, colwidth) - _print_page(io, pages[1], ta, - spacetime, colwidth, nrow, drow, res_row, tophalf, bothalf, - length(pages)) - - if length(pages) > 1 - pndtcols = last(last(pages)) - first(pages[2]) + 1 + # print all columns? + if allcols + for p in pages + islastpage = p == last(pages) + _print_page(io, p, ta, + spacetime, colwidth, nrow, drow, res_row, tophalf, bothalf, + islastpage ? 1 : 2) + if length(pages) > 1 && !islastpage + print(io,"\n\n") + end + end println(io) - printstyled(io, lpad("$pndtcols columns omitted", dcol), color=:cyan) + else + # print first page and omitted columns message + _print_page(io, pages[1], ta, + spacetime, colwidth, nrow, drow, res_row, tophalf, bothalf, + length(pages)) + + if length(pages) > 1 + pndtcols = last(last(pages)) - first(pages[2]) + 1 + println(io) + printstyled(io, lpad("$pndtcols columns omitted", dcol), color=:cyan) + end end end @@ -345,9 +360,12 @@ function _print_page(io::IO, p::UnitRange{Int}, ta::TimeArray, spacetime, end end -Base.show(io::IO, ta::TimeArray) = print_time_array(io, ta, true) -Base.show(io::IO, ::MIME"text/plain", ta::TimeArray) = - print_time_array(io, ta, false) +Base.show(io::IO, ta::TimeArray) = + print_time_array(io, ta, get(io, :limit, false), get(io, :limit, true)) +Base.show(io::IO, ::MIME"text/plain", ta::TimeArray) = + print_time_array(io, ta, false, !get(io, :limit, false)) +Base.show(ta::TimeArray) = + print_time_array(stdout, ta, false, true) ###### getindex ################# diff --git a/test/timearray.jl b/test/timearray.jl index 4c71bf3d..09003d24 100644 --- a/test/timearray.jl +++ b/test/timearray.jl @@ -480,7 +480,7 @@ end @testset "show methods don't throw errors" begin io = IOBuffer() - let str = sprint(show, cl) + let str = sprint(show, cl; context = :limit=>true) out = "500×1 TimeArray{Float64,1,Date,Array{Float64,1}} 2000-01-03 to 2001-12-31" @test str == out end @@ -504,12 +504,13 @@ end │ 2001-12-26 │ 21.49 │ │ 2001-12-27 │ 22.07 │ │ 2001-12-28 │ 22.43 │ -│ 2001-12-31 │ 21.9 │""" +│ 2001-12-31 │ 21.9 │ +""" @test str == out end # my edits above seem to work -- now need to do for the rest, JJS 2/22/19 - let str = sprint(show, ohlc) + let str = sprint(show, ohlc; context = :limit=>true) out = "500×4 TimeArray{Float64,2,Date,Array{Float64,2}} 2000-01-03 to 2001-12-31" @test str == out end @@ -533,15 +534,16 @@ end │ 2001-12-26 │ 21.35 │ 22.3 │ 21.14 │ 21.49 │ │ 2001-12-27 │ 21.58 │ 22.25 │ 21.58 │ 22.07 │ │ 2001-12-28 │ 21.97 │ 23.0 │ 21.96 │ 22.43 │ -│ 2001-12-31 │ 22.51 │ 22.66 │ 21.83 │ 21.9 │""" +│ 2001-12-31 │ 22.51 │ 22.66 │ 21.83 │ 21.9 │ +""" @test str == out end - let str = sprint(show, AAPL) + let str = sprint(show, AAPL; context = :limit => true) out = "8336×12 TimeArray{Float64,2,Date,Array{Float64,2}} 1980-12-12 to 2013-12-31" @test str == out end - show(io, "text/plain", AAPL) + show(IOContext(io, :limit => false), AAPL) let str = String(take!(io)) out = """8336×12 TimeArray{Float64,2,Date,Array{Float64,2}} 1980-12-12 to 2013-12-31 │ │ Open │ High │ Low │ Close │ Volume │ ExDividend │⋯ @@ -565,8 +567,51 @@ end 5 columns omitted""" @test str == out end + show(io, "text/plain", AAPL) + let str = String(take!(io)) + out = """8336×12 TimeArray{Float64,2,Date,Array{Float64,2}} 1980-12-12 to 2013-12-31 +│ │ Open │ High │ Low │ Close │ Volume │ ExDividend │⋯ +├────────────┼────────┼────────┼────────┼────────┼───────────┼────────────┤ +│ 1980-12-12 │ 28.75 │ 28.88 │ 28.75 │ 28.75 │ 2.0939e6 │ 0.0 │ +│ 1980-12-15 │ 27.38 │ 27.38 │ 27.25 │ 27.25 │ 785200.0 │ 0.0 │ +│ 1980-12-16 │ 25.38 │ 25.38 │ 25.25 │ 25.25 │ 472000.0 │ 0.0 │⋯ +│ 1980-12-17 │ 25.88 │ 26.0 │ 25.88 │ 25.88 │ 385900.0 │ 0.0 │ +│ 1980-12-18 │ 26.62 │ 26.75 │ 26.62 │ 26.62 │ 327900.0 │ 0.0 │ +│ 1980-12-19 │ 28.25 │ 28.38 │ 28.25 │ 28.25 │ 217100.0 │ 0.0 │⋯ +│ 1980-12-22 │ 29.62 │ 29.75 │ 29.62 │ 29.62 │ 166800.0 │ 0.0 │ +│ 1980-12-23 │ 30.88 │ 31.0 │ 30.88 │ 30.88 │ 209600.0 │ 0.0 │ +│ ⋮ │ ⋮ │ ⋮ │ ⋮ │ ⋮ │ ⋮ │ ⋮ │ +│ 2013-12-20 │ 545.43 │ 551.61 │ 544.82 │ 549.02 │ 1.55862e7 │ 0.0 │ +│ 2013-12-23 │ 568.0 │ 570.72 │ 562.76 │ 570.09 │ 1.79038e7 │ 0.0 │⋯ +│ 2013-12-24 │ 569.89 │ 571.88 │ 566.03 │ 567.67 │ 5.9841e6 │ 0.0 │ +│ 2013-12-26 │ 568.1 │ 569.5 │ 563.38 │ 563.9 │ 7.286e6 │ 0.0 │ +│ 2013-12-27 │ 563.82 │ 564.41 │ 559.5 │ 560.09 │ 8.0673e6 │ 0.0 │⋯ +│ 2013-12-30 │ 557.46 │ 560.09 │ 552.32 │ 554.52 │ 9.0582e6 │ 0.0 │ +│ 2013-12-31 │ 554.17 │ 561.28 │ 554.0 │ 561.02 │ 7.9673e6 │ 0.0 │ + +│ │ SplitRatio │ AdjOpen │ AdjHigh │ AdjLow │ AdjClose │ +├────────────┼────────────┼──────────┼──────────┼──────────┼──────────┤ +│ 1980-12-12 │ 1.0 │ 3.3766 │ 3.3919 │ 3.3766 │ 3.3766 │ +│ 1980-12-15 │ 1.0 │ 3.2157 │ 3.2157 │ 3.2004 │ 3.2004 │ +│ 1980-12-16 │ 1.0 │ 2.9808 │ 2.9808 │ 2.9655 │ 2.9655 │ +│ 1980-12-17 │ 1.0 │ 3.0395 │ 3.0536 │ 3.0395 │ 3.0395 │ +│ 1980-12-18 │ 1.0 │ 3.1264 │ 3.1417 │ 3.1264 │ 3.1264 │ +│ 1980-12-19 │ 1.0 │ 3.3179 │ 3.3331 │ 3.3179 │ 3.3179 │ +│ 1980-12-22 │ 1.0 │ 3.4788 │ 3.494 │ 3.4788 │ 3.4788 │ +│ 1980-12-23 │ 1.0 │ 3.6267 │ 3.6408 │ 3.6267 │ 3.6267 │ +│ ⋮ │ ⋮ │ ⋮ │ ⋮ │ ⋮ │ ⋮ │ +│ 2013-12-20 │ 1.0 │ 542.2033 │ 548.3467 │ 541.5969 │ 545.7721 │ +│ 2013-12-23 │ 1.0 │ 564.6398 │ 567.3437 │ 559.4308 │ 566.7174 │ +│ 2013-12-24 │ 1.0 │ 566.5186 │ 568.4968 │ 562.6814 │ 564.3117 │ +│ 2013-12-26 │ 1.0 │ 564.7392 │ 566.1309 │ 560.0471 │ 560.564 │ +│ 2013-12-27 │ 1.0 │ 560.4845 │ 561.071 │ 556.1901 │ 556.7766 │ +│ 2013-12-30 │ 1.0 │ 554.1621 │ 556.7766 │ 549.0525 │ 551.2395 │ +│ 2013-12-31 │ 1.0 │ 550.8916 │ 557.9595 │ 550.7226 │ 557.7011 │ +""" + @test str == out + end - let str = sprint(show, ohlc[1:4]) + let str = sprint(show, ohlc[1:4]; context = :limit => true) out = "4×4 TimeArray{Float64,2,Date,Array{Float64,2}} 2000-01-03 to 2000-01-06" @test str == out end @@ -578,12 +623,13 @@ end │ 2000-01-03 │ 104.88 │ 112.5 │ 101.69 │ 111.94 │ │ 2000-01-04 │ 108.25 │ 110.62 │ 101.19 │ 102.5 │ │ 2000-01-05 │ 103.75 │ 110.56 │ 103.0 │ 104.0 │ -│ 2000-01-06 │ 106.12 │ 107.0 │ 95.0 │ 95.0 │""" +│ 2000-01-06 │ 106.12 │ 107.0 │ 95.0 │ 95.0 │ +""" @test str == out end - let str = sprint(show, ohlc[1:0]) + let str = sprint(show, ohlc[1:0]; context = :limit => true) @test str == "0×4 TimeArray{Float64,2,Date,Array{Float64,2}}" end show(io, "text/plain", ohlc[1:0]) @@ -600,7 +646,7 @@ end @test str == "0×1 TimeArray{Any,1,Date,Array{Any,1}}" end - let str = sprint(show, lag(cl[1:2], padding=true)) + let str = sprint(show, lag(cl[1:2], padding=true); context = :limit => true) out = "2×1 TimeArray{Float64,1,Date,Array{Float64,1}} 2000-01-03 to 2000-01-04" @test str == out end @@ -610,7 +656,8 @@ end │ │ Close │ ├────────────┼────────┤ │ 2000-01-03 │ NaN │ -│ 2000-01-04 │ 111.94 │""" +│ 2000-01-04 │ 111.94 │ +""" @test str == out end end # @testset "show methods don't throw errors" From 658b8a530d3b2bdc6f907d5387dee6c47971fb24 Mon Sep 17 00:00:00 2001 From: Rodrigo Chang Date: Mon, 29 Mar 2021 19:43:11 -0600 Subject: [PATCH 4/6] Apply suggestions from code review Co-authored-by: Iblis Lin --- src/timearray.jl | 4 +++- test/timearray.jl | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/timearray.jl b/src/timearray.jl index f17fc07c..23b72a3e 100644 --- a/src/timearray.jl +++ b/src/timearray.jl @@ -360,8 +360,10 @@ function _print_page(io::IO, p::UnitRange{Int}, ta::TimeArray, spacetime, end end +Base.summary(io::IO, ta::TimeArray) = print_time_array(io, ta, true) + Base.show(io::IO, ta::TimeArray) = - print_time_array(io, ta, get(io, :limit, false), get(io, :limit, true)) + print_time_array(io, ta, false, get(io, :limit, true)) Base.show(io::IO, ::MIME"text/plain", ta::TimeArray) = print_time_array(io, ta, false, !get(io, :limit, false)) Base.show(ta::TimeArray) = diff --git a/test/timearray.jl b/test/timearray.jl index 09003d24..1d293f27 100644 --- a/test/timearray.jl +++ b/test/timearray.jl @@ -510,7 +510,7 @@ end end # my edits above seem to work -- now need to do for the rest, JJS 2/22/19 - let str = sprint(show, ohlc; context = :limit=>true) + let str = sprint(summary, ohlc) out = "500×4 TimeArray{Float64,2,Date,Array{Float64,2}} 2000-01-03 to 2001-12-31" @test str == out end From cb386fa1f00d448079f1af45fd45f5fd374c4827 Mon Sep 17 00:00:00 2001 From: Rodrigo Chang Date: Tue, 30 Mar 2021 13:38:30 -0600 Subject: [PATCH 5/6] Changed show tests to use summary - Removed last newline - Removed individual show method --- src/timearray.jl | 3 --- test/timearray.jl | 28 +++++++++++++--------------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/timearray.jl b/src/timearray.jl index 23b72a3e..acd6cea7 100644 --- a/src/timearray.jl +++ b/src/timearray.jl @@ -272,7 +272,6 @@ function print_time_array(io::IO, ta::TimeArray{T}, short=false, allcols=false) print(io,"\n\n") end end - println(io) else # print first page and omitted columns message _print_page(io, pages[1], ta, @@ -366,8 +365,6 @@ Base.show(io::IO, ta::TimeArray) = print_time_array(io, ta, false, get(io, :limit, true)) Base.show(io::IO, ::MIME"text/plain", ta::TimeArray) = print_time_array(io, ta, false, !get(io, :limit, false)) -Base.show(ta::TimeArray) = - print_time_array(stdout, ta, false, true) ###### getindex ################# diff --git a/test/timearray.jl b/test/timearray.jl index 1d293f27..2da8751b 100644 --- a/test/timearray.jl +++ b/test/timearray.jl @@ -480,7 +480,7 @@ end @testset "show methods don't throw errors" begin io = IOBuffer() - let str = sprint(show, cl; context = :limit=>true) + let str = sprint(summary, cl) out = "500×1 TimeArray{Float64,1,Date,Array{Float64,1}} 2000-01-03 to 2001-12-31" @test str == out end @@ -504,8 +504,7 @@ end │ 2001-12-26 │ 21.49 │ │ 2001-12-27 │ 22.07 │ │ 2001-12-28 │ 22.43 │ -│ 2001-12-31 │ 21.9 │ -""" +│ 2001-12-31 │ 21.9 │""" @test str == out end @@ -534,12 +533,11 @@ end │ 2001-12-26 │ 21.35 │ 22.3 │ 21.14 │ 21.49 │ │ 2001-12-27 │ 21.58 │ 22.25 │ 21.58 │ 22.07 │ │ 2001-12-28 │ 21.97 │ 23.0 │ 21.96 │ 22.43 │ -│ 2001-12-31 │ 22.51 │ 22.66 │ 21.83 │ 21.9 │ -""" +│ 2001-12-31 │ 22.51 │ 22.66 │ 21.83 │ 21.9 │""" @test str == out end - let str = sprint(show, AAPL; context = :limit => true) + let str = sprint(summary, AAPL) out = "8336×12 TimeArray{Float64,2,Date,Array{Float64,2}} 1980-12-12 to 2013-12-31" @test str == out end @@ -606,12 +604,11 @@ end │ 2013-12-26 │ 1.0 │ 564.7392 │ 566.1309 │ 560.0471 │ 560.564 │ │ 2013-12-27 │ 1.0 │ 560.4845 │ 561.071 │ 556.1901 │ 556.7766 │ │ 2013-12-30 │ 1.0 │ 554.1621 │ 556.7766 │ 549.0525 │ 551.2395 │ -│ 2013-12-31 │ 1.0 │ 550.8916 │ 557.9595 │ 550.7226 │ 557.7011 │ -""" +│ 2013-12-31 │ 1.0 │ 550.8916 │ 557.9595 │ 550.7226 │ 557.7011 │""" @test str == out end - let str = sprint(show, ohlc[1:4]; context = :limit => true) + let str = sprint(summary, ohlc[1:4]) out = "4×4 TimeArray{Float64,2,Date,Array{Float64,2}} 2000-01-03 to 2000-01-06" @test str == out end @@ -623,13 +620,15 @@ end │ 2000-01-03 │ 104.88 │ 112.5 │ 101.69 │ 111.94 │ │ 2000-01-04 │ 108.25 │ 110.62 │ 101.19 │ 102.5 │ │ 2000-01-05 │ 103.75 │ 110.56 │ 103.0 │ 104.0 │ -│ 2000-01-06 │ 106.12 │ 107.0 │ 95.0 │ 95.0 │ -""" +│ 2000-01-06 │ 106.12 │ 107.0 │ 95.0 │ 95.0 │""" @test str == out end - let str = sprint(show, ohlc[1:0]; context = :limit => true) + let str = sprint(show, ohlc[1:0]) + @test str == "0×4 TimeArray{Float64,2,Date,Array{Float64,2}}" + end + let str = sprint(summary, ohlc[1:0]) @test str == "0×4 TimeArray{Float64,2,Date,Array{Float64,2}}" end show(io, "text/plain", ohlc[1:0]) @@ -646,7 +645,7 @@ end @test str == "0×1 TimeArray{Any,1,Date,Array{Any,1}}" end - let str = sprint(show, lag(cl[1:2], padding=true); context = :limit => true) + let str = sprint(summary, lag(cl[1:2], padding=true)) out = "2×1 TimeArray{Float64,1,Date,Array{Float64,1}} 2000-01-03 to 2000-01-04" @test str == out end @@ -656,8 +655,7 @@ end │ │ Close │ ├────────────┼────────┤ │ 2000-01-03 │ NaN │ -│ 2000-01-04 │ 111.94 │ -""" +│ 2000-01-04 │ 111.94 │""" @test str == out end end # @testset "show methods don't throw errors" From 42f4ca448c108a74dfadf19595fed7d4a8b4cafd Mon Sep 17 00:00:00 2001 From: Rodrigo Chang Date: Wed, 31 Mar 2021 10:41:53 -0600 Subject: [PATCH 6/6] Change show tests to support Julia 1.6 --- test/timearray.jl | 50 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/test/timearray.jl b/test/timearray.jl index 2da8751b..0379c27c 100644 --- a/test/timearray.jl +++ b/test/timearray.jl @@ -478,15 +478,33 @@ end end +# String shown in TimeArray header depends on Julia version +function disptype(ta::TimeArray) + datetype, datatype = eltype(ta).types + datatype = eltype(datatype) + n = ndims(ta) + datastr = repr(datatype) + datestr = repr(datetype) + + if VERSION < v"1.6" + str_repr = "TimeArray{$datastr,$n,$datestr,Array{$datastr,$n}}" + else + # In Julia 1.6 it shows with spaces and aliases + last = n > 1 ? "Matrix{$datastr}" : "Vector{$datastr}" + str_repr = "TimeArray{$datastr, $n, $datestr, $last}" + end + str_repr +end + @testset "show methods don't throw errors" begin io = IOBuffer() let str = sprint(summary, cl) - out = "500×1 TimeArray{Float64,1,Date,Array{Float64,1}} 2000-01-03 to 2001-12-31" + out = "500×1 $(disptype(cl)) 2000-01-03 to 2001-12-31" @test str == out end show(io, "text/plain", cl) let str = String(take!(io)) - out = """500×1 TimeArray{Float64,1,Date,Array{Float64,1}} 2000-01-03 to 2001-12-31 + out = """500×1 $(disptype(cl)) 2000-01-03 to 2001-12-31 │ │ Close │ ├────────────┼────────┤ │ 2000-01-03 │ 111.94 │ @@ -510,12 +528,12 @@ end # my edits above seem to work -- now need to do for the rest, JJS 2/22/19 let str = sprint(summary, ohlc) - out = "500×4 TimeArray{Float64,2,Date,Array{Float64,2}} 2000-01-03 to 2001-12-31" + out = "500×4 $(disptype(ohlc)) 2000-01-03 to 2001-12-31" @test str == out end show(io, "text/plain", ohlc) let str = String(take!(io)) - out = """500×4 TimeArray{Float64,2,Date,Array{Float64,2}} 2000-01-03 to 2001-12-31 + out = """500×4 $(disptype(ohlc)) 2000-01-03 to 2001-12-31 │ │ Open │ High │ Low │ Close │ ├────────────┼────────┼────────┼────────┼────────┤ │ 2000-01-03 │ 104.88 │ 112.5 │ 101.69 │ 111.94 │ @@ -538,12 +556,12 @@ end end let str = sprint(summary, AAPL) - out = "8336×12 TimeArray{Float64,2,Date,Array{Float64,2}} 1980-12-12 to 2013-12-31" + out = "8336×12 $(disptype(AAPL)) 1980-12-12 to 2013-12-31" @test str == out end show(IOContext(io, :limit => false), AAPL) let str = String(take!(io)) - out = """8336×12 TimeArray{Float64,2,Date,Array{Float64,2}} 1980-12-12 to 2013-12-31 + out = """8336×12 $(disptype(AAPL)) 1980-12-12 to 2013-12-31 │ │ Open │ High │ Low │ Close │ Volume │ ExDividend │⋯ ├────────────┼────────┼────────┼────────┼────────┼───────────┼────────────┤ │ 1980-12-12 │ 28.75 │ 28.88 │ 28.75 │ 28.75 │ 2.0939e6 │ 0.0 │ @@ -567,7 +585,7 @@ end end show(io, "text/plain", AAPL) let str = String(take!(io)) - out = """8336×12 TimeArray{Float64,2,Date,Array{Float64,2}} 1980-12-12 to 2013-12-31 + out = """8336×12 $(disptype(AAPL)) 1980-12-12 to 2013-12-31 │ │ Open │ High │ Low │ Close │ Volume │ ExDividend │⋯ ├────────────┼────────┼────────┼────────┼────────┼───────────┼────────────┤ │ 1980-12-12 │ 28.75 │ 28.88 │ 28.75 │ 28.75 │ 2.0939e6 │ 0.0 │ @@ -609,12 +627,12 @@ end end let str = sprint(summary, ohlc[1:4]) - out = "4×4 TimeArray{Float64,2,Date,Array{Float64,2}} 2000-01-03 to 2000-01-06" + out = "4×4 $(disptype(ohlc[1:4])) 2000-01-03 to 2000-01-06" @test str == out end show(io, "text/plain", ohlc[1:4]) let str = String(take!(io)) - out = """4×4 TimeArray{Float64,2,Date,Array{Float64,2}} 2000-01-03 to 2000-01-06 + out = """4×4 $(disptype(ohlc[1:4])) 2000-01-03 to 2000-01-06 │ │ Open │ High │ Low │ Close │ ├────────────┼────────┼────────┼────────┼────────┤ │ 2000-01-03 │ 104.88 │ 112.5 │ 101.69 │ 111.94 │ @@ -626,32 +644,32 @@ end let str = sprint(show, ohlc[1:0]) - @test str == "0×4 TimeArray{Float64,2,Date,Array{Float64,2}}" + @test str == "0×4 $(disptype(ohlc[1:0]))" end let str = sprint(summary, ohlc[1:0]) - @test str == "0×4 TimeArray{Float64,2,Date,Array{Float64,2}}" + @test str == "0×4 $(disptype(ohlc[1:0]))" end show(io, "text/plain", ohlc[1:0]) let str = String(take!(io)) - @test str == "0×4 TimeArray{Float64,2,Date,Array{Float64,2}}" + @test str == "0×4 $(disptype(ohlc[1:0]))" end let str = sprint(show, TimeArray(Date[], [])) - @test str == "0×1 TimeArray{Any,1,Date,Array{Any,1}}" + @test str == "0×1 $(disptype(TimeArray(Date[], [])))" end show(io, "text/plain", TimeArray(Date[], [])) let str = String(take!(io)) - @test str == "0×1 TimeArray{Any,1,Date,Array{Any,1}}" + @test str == "0×1 $(disptype(TimeArray(Date[], [])))" end let str = sprint(summary, lag(cl[1:2], padding=true)) - out = "2×1 TimeArray{Float64,1,Date,Array{Float64,1}} 2000-01-03 to 2000-01-04" + out = "2×1 $(disptype(lag(cl[1:2], padding=true))) 2000-01-03 to 2000-01-04" @test str == out end show(io, "text/plain", lag(cl[1:2], padding=true)) let str = String(take!(io)) - out = """2×1 TimeArray{Float64,1,Date,Array{Float64,1}} 2000-01-03 to 2000-01-04 + out = """2×1 $(disptype(lag(cl[1:2], padding=true))) 2000-01-03 to 2000-01-04 │ │ Close │ ├────────────┼────────┤ │ 2000-01-03 │ NaN │