JuliaStats / TimeSeries.jl

Time series toolkit for Julia
Other
353 stars 69 forks source link

timearray: refine pretty printing #331

Closed iblislin closed 7 years ago

iblislin commented 7 years ago

Sample output:

julia> ohlc
500x4 TimeSeries.TimeArray{Float64,2,Date,Array{Float64,2}} 2000-01-03 to 2001-12-31
│            │ TestSoLong │ High   │ Low    │ Close  │
├────────────┼────────────┼────────┼────────┼────────┤
│ 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-07 │ 96.5       │ 101.0  │ 95.5   │ 99.5   │
│ 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  │
│ 2000-01-14 │ 100.0      │ 102.25 │ 99.38  │ 100.44 │
│ 2000-01-18 │ 101.0      │ 106.0  │ 100.44 │ 103.94 │
│ 2000-01-19 │ 105.62     │ 108.75 │ 103.38 │ 106.56 │
   ⋮
│ 2001-12-14 │ 20.73      │ 20.83  │ 20.09  │ 20.39  │
│ 2001-12-17 │ 20.4       │ 21.0   │ 20.19  │ 20.62  │
│ 2001-12-18 │ 20.89      │ 21.33  │ 20.22  │ 21.01  │
│ 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  │
│ 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   │

julia>
iblislin commented 7 years ago

this PR should fix #330

coveralls commented 7 years ago

Coverage Status

Coverage increased (+0.5%) to 85.851% when pulling e79283472d28e6f4139f83ac702dbc556986830b on iblis17:refine-show into dde2b8e01c4753cb80a8cc2a5e9428e8d865dd97 on JuliaStats:master.

ararslan commented 7 years ago

That output looks really nice. Good work! It might be worthwhile to add a test that ensures that sprint(show, ta) (for ta a TimeArray) matches some expected output string.

coveralls commented 7 years ago

Coverage Status

Coverage increased (+0.5%) to 85.851% when pulling 0f7d37cd8d64921b16b1a063ab4c139c5638ea0d on iblis17:refine-show into dde2b8e01c4753cb80a8cc2a5e9428e8d865dd97 on JuliaStats:master.

iblislin commented 7 years ago

simple test cases added.

iblislin commented 7 years ago

good to go?

ararslan commented 7 years ago

I think there should be a test along the lines of

@test sprint(show, something) == """
│            │ TestSoLong │ High   │ Low    │ Close  │
├────────────┼────────────┼────────┼────────┼────────┤
│ 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-07 │ 96.5       │ 101.0  │ 95.5   │ 99.5   │
│ 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  │
│ 2000-01-14 │ 100.0      │ 102.25 │ 99.38  │ 100.44 │
│ 2000-01-18 │ 101.0      │ 106.0  │ 100.44 │ 103.94 │
│ 2000-01-19 │ 105.62     │ 108.75 │ 103.38 │ 106.56 │
"""

This ensures that the column alignment, rounding, values, and all of that is as expected. It's a more exact test than using contains.

iblislin commented 7 years ago

👌 done

coveralls commented 7 years ago

Coverage Status

Coverage increased (+0.5%) to 85.851% when pulling 19e3c859413b1b938cac2113e1e09dd00a12860d on iblis17:refine-show into 6b590f8f039f339e3f649edca692c5708c431b27 on JuliaStats:master.