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

Fixes for non-ordered intervals #51

Merged
merged 4 commits into from Aug 14, 2018
Merged

Fixes for non-ordered intervals #51

merged 4 commits into from Aug 14, 2018

Conversation

omus
Copy link
Collaborator

@omus omus commented Aug 14, 2018

No description provided.

Copy link
Contributor

@ararslan ararslan left a comment

Choose a reason for hiding this comment

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

Looks good to me

@omus
Copy link
Collaborator Author

omus commented Aug 14, 2018

Found one more change to make

@codecov
Copy link

codecov bot commented Aug 14, 2018

Codecov Report

Merging #51 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #51      +/-   ##
==========================================
+ Coverage   98.23%   98.26%   +0.02%     
==========================================
  Files           6        6              
  Lines         227      230       +3     
==========================================
+ Hits          223      226       +3     
  Misses          4        4
Impacted Files Coverage Δ
src/anchoredinterval.jl 98.24% <100%> (+0.03%) ⬆️
src/interval.jl 97% <100%> (+0.06%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 74c9ff0...b436ac7. Read the comment docs.

Base.first(interval::AnchoredInterval{P}) where P = min(interval.anchor, interval.anchor+P)
Base.last(interval::AnchoredInterval{P}) where P = max(interval.anchor, interval.anchor+P)
function Base.first(interval::AnchoredInterval{P}) where P
if P < zero(P)
Copy link
Member

Choose a reason for hiding this comment

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

I'd write this as a ternary I guess.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I thought it was visually too busy with the +:

function Base.first(interval::AnchoredInterval{P}) where P
    P < zero(P) ? interval.anchor + P : interval.anchor
end

Copy link
Contributor

Choose a reason for hiding this comment

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

You could alternatively write it as interval.anchor + P * (P < zero(P)) 😛

Copy link
Member

@rofinn rofinn Aug 14, 2018

Choose a reason for hiding this comment

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

Also, we may want to just store the extrema as a tuple in the immutable type rather than performing this check every time. I think that would make the code cleaner too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is more complicated than it first seems see: #52

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll go with a ternary statement with parameters around it. @ararslan's suggestion is good but there's an issue we need to solve with LaxZonedDateTimes which can result in the answer being wrong with you add a TimePeriod of 0...

Copy link
Contributor

Choose a reason for hiding this comment

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

I was joking, really. Using a conditional, be it if or ternary, seems better to me.

@@ -223,6 +223,10 @@ end

##### EQUALITY #####

function Base.:(==)(a::AnchoredInterval{P, T}, b::AnchoredInterval{P, T}) where {P, T}
Copy link
Member

@rofinn rofinn Aug 14, 2018

Choose a reason for hiding this comment

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

Should we implement isequal here as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can safely fall back to isequal(::AbstractInterval, ::AbstractInterval) here. I'll add some tests though to make sure we have the proper behaviour.

@@ -121,8 +121,14 @@ end

##### ACCESSORS #####

Base.first(interval::AnchoredInterval{P}) where P = min(interval.anchor, interval.anchor+P)
Base.last(interval::AnchoredInterval{P}) where P = max(interval.anchor, interval.anchor+P)
function Base.first(interval::AnchoredInterval{P}) where P
Copy link
Member

Choose a reason for hiding this comment

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

Don't forget to add a comment on why min and max won't work :)

@rofinn
Copy link
Member

rofinn commented Aug 14, 2018

Alright, I'm fine waiting to store the extrema in the type till later. LGTM.

@@ -121,6 +121,12 @@ end

##### ACCESSORS #####

# Note: For `first` and `last` the typically we would compute this is using `min` and `max`.
Copy link
Member

Choose a reason for hiding this comment

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

"We would typically compute first and last using min and max respectively, but we can get unexpected behaviour if adding the span to the endpoint produces a value that is no longer comparable (e.g., NaN)."?

@rofinn rofinn merged commit 6f5b07a into master Aug 14, 2018
@omus omus deleted the cv/non-ordered branch August 14, 2018 21:39
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

3 participants