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

timearray: Revoke deprecation of == and redefine its meaning #357

Merged
merged 9 commits into from
Dec 30, 2017

Conversation

iblislin
Copy link
Collaborator

julia> cl == copy(cl)
true

@dourouc05 please review this

```julia
julia> cl == copy(cl)
true
```
@codecov-io
Copy link

codecov-io commented Dec 25, 2017

Codecov Report

Merging #357 into master will increase coverage by 0.23%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #357      +/-   ##
==========================================
+ Coverage   85.98%   86.22%   +0.23%     
==========================================
  Files          10       10              
  Lines         471      479       +8     
==========================================
+ Hits          405      413       +8     
  Misses         66       66
Impacted Files Coverage Δ
src/timearray.jl 98.49% <100%> (+0.09%) ⬆️

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 b66a385...dab9ae1. Read the comment docs.

@iblislin iblislin added this to the 0.12.0 milestone Dec 25, 2017
@dourouc05
Copy link
Contributor

It works fine for me! (I have never really played with generated functions, so don't count me in for the code review.)

Maybe the docstring could me more informative for users? I am not sure beginners will know what fields a TimeArray has. This is what I propose:

If true, all fields of x and y should be equal, meaning that the two time arrays have the same values at the same points in time, and the same metadata.

@iblislin
Copy link
Collaborator Author

ok, I updated it

src/timearray.jl Outdated
x.meta == y.meta
```
"""
@generated function ==(x::TimeArray{T,N}, y::TimeArray{S,M}) where {T,S,N,M}
Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't require a generated function.

Base.:(==)(x::TimeArray{T,N}, y::TimeArray{S,N}) where {T,S,N} =
    all(f->getfield(x, f) == getfield(y, f), fieldnames(TimeArray))
Base.:(==)(x::TimeArray{T,N}, y::TimeArray{S,M}) where {T,S,N,M} = false

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Wow, it's elegant.
TIL, all will do early stopping.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

and done in following commits

src/timearray.jl Outdated

# support for Dict
hash(x::TimeArray, h::UInt) =
mapreduce(+, fieldnames(TimeArray)) do f
Copy link
Member

Choose a reason for hiding this comment

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

sum is mapreduce(+, ...) so this can be written

Base.hash(x::TimeArray, h::UInt) = sum(f->hash(getfield(x, f), h), fieldnames(TimeArray))

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

NEWS.md Outdated
### 0.12.0

* Revoking deprecation warning of `==` and redefining its meaning as
'comparing all fields of two TimeArray'. (#356, #357)
Copy link
Member

Choose a reason for hiding this comment

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

It would also be good to note here that two TimeArrays compare unequal if they have different dimensions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@iblislin
Copy link
Collaborator Author

good to go?

@iblislin iblislin merged commit c96374c into master Dec 30, 2017
@iblislin iblislin deleted the ib/equal branch December 30, 2017 04:33
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.

4 participants