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

allow views of timestamps in constructors #313

Merged
merged 17 commits into from
Jun 3, 2017
Merged

allow views of timestamps in constructors #313

merged 17 commits into from
Jun 3, 2017

Conversation

JeffreySarnoff
Copy link
Contributor

@JeffreySarnoff JeffreySarnoff commented Jun 1, 2017

allows TimeArrays to be constructed from view_s of another TimeArray's timestamps
just as TimeArrays can be constructed from view_s of another TimeArray's values

@coveralls
Copy link

Coverage Status

Coverage increased (+0.04%) to 84.673% when pulling eafb6dc on JeffreySarnoff:views into a1151d9 on JuliaStats:master.

@ararslan
Copy link
Member

ararslan commented Jun 1, 2017

Nice, thanks! Could you add a test for the new functionality?

@JeffreySarnoff
Copy link
Contributor Author

I have not used that style of test -- the old way the test would be e.g.

    items = 101:121
    cols = 1:size(AAPL.values)[2]
    tstamps = view(AAPL.timestamp, items)
    tvalues = view(AAPL.values, items, cols)
    APPL2 = TimeArray(tstamps, tvalues, AAPL.colnames, AAPL.meta)
    
    @test AAPL[101:121] == AAPL2[1:end]

tvalues = view(AAPL.values, items, cols)
APPL2 = TimeArray(tstamps, tvalues, AAPL.colnames, AAPL.meta)

@test AAPL[101:121] == AAPL2[1:end]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a macro @fact from FactCheck...

@ararslan
Copy link
Member

ararslan commented Jun 1, 2017

Yes, as @iblis17 points out, this repository unfortunately still uses the outdated FactCheck package for its testing rather than the unit testing functionality provided in Base. To turn a @test into a @fact, you do @fact a --> b rather than @test a == b.

@JeffreySarnoff
Copy link
Contributor Author

I do not see the problem -- it works for me with cut and paste

tstamps = view(AAPL.timestamp, source_rows)
tvalues = view(AAPL.values, source_rows, source_cols)

APPL2 = TimeArray(tstamps, tvalues, AAPL.colnames, AAPL.meta)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ha, I got it. APPL2 is typo

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be AAPL2

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☕ very good noticing 🍇

facts("type constructors allow views") do

source_rows = 101:121
source_cols = 1:size(AAPL.values)[2]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please purge the trailing whitespace :)

@coveralls
Copy link

Coverage Status

Coverage increased (+0.04%) to 84.673% when pulling 93feab5 on JeffreySarnoff:views into a1151d9 on JuliaStats:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.04%) to 84.673% when pulling c87eaca on JeffreySarnoff:views into a1151d9 on JuliaStats:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.04%) to 84.673% when pulling 8341300 on JeffreySarnoff:views into a1151d9 on JuliaStats:master.

@ararslan
Copy link
Member

ararslan commented Jun 3, 2017

Looks great, thanks for the contribution!

@ararslan ararslan merged commit 67a73a8 into JuliaStats:master Jun 3, 2017
@milktrader
Copy link
Contributor

Should we move away from FactCheck? I guess this is probably an important issue.

@JeffreySarnoff
Copy link
Contributor Author

yes

@ararslan
Copy link
Member

ararslan commented Jun 8, 2017

Yes, definitely. I believe it's no longer actively maintained, plus the Base unit testing framework is fantastic.

@JeffreySarnoff
Copy link
Contributor Author

In a general way -- the timestamp vector and the values array can be view()ed and the views used as args.
Currently, the colnames vector does not share that facility. Would it be helpful to add that?

@iblislin
Copy link
Collaborator

iblislin commented Jun 8, 2017

@ararslan Here is the blocker I encountered: JuliaQuant/MarketTechnicals.jl#70 (comment)

Our testing relies on tons of roughly, but the sweet macro is only available in 0.6.

@JeffreySarnoff
Copy link
Contributor Author

JeffreySarnoff commented Jun 8, 2017

roughly is defined using isapprox

# approx/roughly: Comparing numbers approximately
roughly(x::Number, atol) = (y::Number) -> isapprox(y, x, atol=atol)

roughly(x::Number; kvtols...) = (y::Number) -> isapprox(y, x; kvtols...)

roughly(A::AbstractArray, atol) = (B::AbstractArray) -> begin
    size(A) != size(B) && return false
    return isapprox(A, B, atol=atol)
end

roughly(A::AbstractArray; kvtols...) = (B::AbstractArray) -> begin
    size(A) != size(B) && return false
    return isapprox(A, B; kvtols...)
end

As the tests use roughly, why not add the above into runtests.jl?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants