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

Fix AlignedSpan(..., ::AlignedSpan, ...) and add test #11

Merged
merged 3 commits into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "AlignedSpans"
uuid = "72438786-fd5d-49ef-8843-650acbdfe662"
authors = ["Beacon Biosignals, Inc."]
version = "0.2.0"
version = "0.2.1"

[deps]
ArrowTypes = "31f734f8-188a-4ce0-8406-c8a06bd891cd"
Expand Down
1 change: 0 additions & 1 deletion src/interop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ TimeSpans.stop(span::AlignedSpan) = time_from_index(span.sample_rate, span.last_
# TimeSpan -> AlignedSpan is supported by passing to Intervals
to_interval(span) = Interval{Nanosecond,Closed,Open}(start(span), stop(span))
to_interval(span::Interval) = span
to_interval(span::AlignedSpan) = Interval(span)
Comment on lines 49 to -50
Copy link
Member

Choose a reason for hiding this comment

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

does this count as breaking?

Copy link
Member Author

Choose a reason for hiding this comment

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

No bc this actually errored (no such Interval constructor existed), but removing this dispatch means we hit the fallback which works successfully (as the test shows).


# Interface methods:

Expand Down
17 changes: 3 additions & 14 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,6 @@ function make_test_samples(sample_rate)
sample_rate), false)
end

# Interop with `StepRange`
function Base.StepRange(span::AlignedSpan)
# the rounding here is not ideal
t = Nanosecond(round(Int, TimeSpans.nanoseconds_per_sample(span.sample_rate)))
return (span.i * t):t:(span.j * t)
end

function AlignedSpan(r::StepRange{T,S}) where {T<:Period,S<:Period}
sample_rate = TimeSpans.NS_IN_SEC / Dates.value(convert(Nanosecond, step(r)))
i = first(r) / step(r)
j = last(r) / step(r)
return AlignedSpan(sample_rate, Int(i), Int(j))
end

@testset "AlignedSpans.jl" begin
@testset "Aqua" begin
Aqua.test_all(AlignedSpans; ambiguities=false)
Expand Down Expand Up @@ -70,6 +56,9 @@ end
span = TimeSpan(Millisecond(1999), Millisecond(2000))
aligned = AlignedSpan(1, span, RoundSpanDown)
@test indices(aligned) == 2:2

# Test that we can pass an `AlignedSpan` back into the constructor
@test AlignedSpan(1, aligned, RoundSpanDown) == aligned
end

@testset "ConstantSamplesRoundingMode" begin
Expand Down