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

RFC: Fix #12074 and #12094 #12115

Merged
merged 1 commit into from
Jul 13, 2015
Merged

Conversation

GordStephen
Copy link
Contributor

This resolves #12074 and #12094 by cleaning up and completing #12084.

Implements:

  • Subtraction between TimeType arrays
  • Addition/subtraction between Period/CompoundPeriod arrays
  • Addtion/subtraction between TimeType and Period/CompoundPeriod arrays
  • Broadcasting of scalar TimeType/Period/CompoundPeriod addition/subtraction over TimeType/Period/CompoundPeriod arrays
  • Tests for all of the above

…roadcasting (where not previously implemented)
@tkelman
Copy link
Contributor

tkelman commented Jul 11, 2015

cc @quinnj

@quinnj quinnj merged commit bed9d29 into JuliaLang:master Jul 13, 2015
@quinnj
Copy link
Member

quinnj commented Jul 13, 2015

Thanks @GordStephen for digging into this and ironing out the details here. Also thanks for the good # of tests. If you're interested in taking a crack at improving the Dates parsing code, I'm sure @jiahao would appreciate it (there should be a few open issues); I'm always happen to recruit people to work on Dates stuff.

@jiahao
Copy link
Member

jiahao commented Jul 14, 2015

Always appreciate more work on Dates.

Unfortunately this PR introduced a very large number of ambiguity warnings downstream. For example:

julia> using DataFrames
Warning: New definition 
    +(AbstractArray, DataArrays.DataArray) at /Users/jiahao/.julia/v0.4/DataArrays/src/operators.jl:326
is ambiguous with: 
    +(Union{DenseArray{#P<:Union{Base.Dates.CompoundPeriod, Base.Dates.Period}, N<:Any}, Base.SubArray{#P<:Union{Base.Dates.CompoundPeriod, Base.Dates.Period}, N<:Any, A<:DenseArray, I<:Tuple{Vararg{Union{Int64, Base.Range{Int64}, Base.Colon}}}, LD<:Any}}, AbstractArray{#T<:Base.Dates.TimeType, N<:Any}) at dates/arithmetic.jl:90.
To fix, define 
    +(Union{DenseArray{#P<:Union{Base.Dates.CompoundPeriod, Base.Dates.Period}, N<:Any}, Base.SubArray{#P<:Union{Base.Dates.CompoundPeriod, Base.Dates.Period}, N<:Any, A<:DenseArray, I<:Tuple{Vararg{Union{Int64, Base.Range{Int64}, Base.Colon}}}, LD<:Any}}, DataArrays.DataArray{#T<:Base.Dates.TimeType, N<:Any})
before the new definition.
Warning: New definition 
    +(AbstractArray, DataArrays.AbstractDataArray) at /Users/jiahao/.julia/v0.4/DataArrays/src/operators.jl:349
is ambiguous with: 
    +(Union{DenseArray{#P<:Union{Base.Dates.CompoundPeriod, Base.Dates.Period}, N<:Any}, Base.SubArray{#P<:Union{Base.Dates.CompoundPeriod, Base.Dates.Period}, N<:Any, A<:DenseArray, I<:Tuple{Vararg{Union{Int64, Base.Range{Int64}, Base.Colon}}}, LD<:Any}}, AbstractArray{#T<:Base.Dates.TimeType, N<:Any}) at dates/arithmetic.jl:90.
To fix, define 
    +(Union{DenseArray{#P<:Union{Base.Dates.CompoundPeriod, Base.Dates.Period}, N<:Any}, Base.SubArray{#P<:Union{Base.Dates.CompoundPeriod, Base.Dates.Period}, N<:Any, A<:DenseArray, I<:Tuple{Vararg{Union{Int64, Base.Range{Int64}, Base.Colon}}}, LD<:Any}}, DataArrays.AbstractDataArray{#T<:Base.Dates.TimeType, N<:Any})
before the new definition.
Warning: New definition 
    -(Base.Range, DataArrays.DataArray) at /Users/jiahao/.julia/v0.4/DataArrays/src/operators.jl:326
is ambiguous with: 
    -(Base.Range{#T<:Base.Dates.TimeType}, AbstractArray{#T<:Base.Dates.TimeType, N<:Any}) at dates/arithmetic.jl:104.
To fix, define 
    -(Base.Range{#T<:Base.Dates.TimeType}, DataArrays.DataArray{#T<:Base.Dates.TimeType, N<:Any})
before the new definition.
Warning: New definition 
    -(AbstractArray, DataArrays.DataArray) at /Users/jiahao/.julia/v0.4/DataArrays/src/operators.jl:326
is ambiguous with: 
    -(Union{DenseArray{#P<:Union{Base.Dates.CompoundPeriod, Base.Dates.Period}, N<:Any}, Base.SubArray{#P<:Union{Base.Dates.CompoundPeriod, Base.Dates.Period}, N<:Any, A<:DenseArray, I<:Tuple{Vararg{Union{Int64, Base.Range{Int64}, Base.Colon}}}, LD<:Any}}, AbstractArray{#T<:Base.Dates.TimeType, N<:Any}) at dates/arithmetic.jl:90.
To fix, define 
    -(Union{DenseArray{#P<:Union{Base.Dates.CompoundPeriod, Base.Dates.Period}, N<:Any}, Base.SubArray{#P<:Union{Base.Dates.CompoundPeriod, Base.Dates.Period}, N<:Any, A<:DenseArray, I<:Tuple{Vararg{Union{Int64, Base.Range{Int64}, Base.Colon}}}, LD<:Any}}, DataArrays.DataArray{#T<:Base.Dates.TimeType, N<:Any})
before the new definition.
Warning: New definition 
    -(AbstractArray, DataArrays.DataArray) at /Users/jiahao/.julia/v0.4/DataArrays/src/operators.jl:326
is ambiguous with: 
    -(Base.Range{#T<:Base.Dates.TimeType}, AbstractArray{#T<:Base.Dates.TimeType, N<:Any}) at dates/arithmetic.jl:104.
To fix, define 
    -(Base.Range{#T<:Base.Dates.TimeType}, DataArrays.DataArray{#T<:Base.Dates.TimeType, N<:Any})
before the new definition.
Warning: New definition 
    -(AbstractArray, DataArrays.DataArray) at /Users/jiahao/.julia/v0.4/DataArrays/src/operators.jl:326
is ambiguous with: 
    -(AbstractArray{#T<:Base.Dates.TimeType, N<:Any}, AbstractArray{#T<:Base.Dates.TimeType, N<:Any}) at dates/arithmetic.jl:105.
To fix, define 
    -(AbstractArray{#T<:Base.Dates.TimeType, N<:Any}, DataArrays.DataArray{#T<:Base.Dates.TimeType, N<:Any})
before the new definition.
Warning: New definition 
    -(DataArrays.AbstractDataArray, Base.Range) at /Users/jiahao/.julia/v0.4/DataArrays/src/operators.jl:349
is ambiguous with: 
    -(AbstractArray{#T<:Base.Dates.TimeType, N<:Any}, Base.Range{#T<:Base.Dates.TimeType}) at dates/arithmetic.jl:103.
To fix, define 
    -(DataArrays.AbstractDataArray{#T<:Base.Dates.TimeType, N<:Any}, Base.Range{#T<:Base.Dates.TimeType})
before the new definition.
Warning: New definition 
    -(Base.Range, DataArrays.AbstractDataArray) at /Users/jiahao/.julia/v0.4/DataArrays/src/operators.jl:349
is ambiguous with: 
    -(Base.Range{#T<:Base.Dates.TimeType}, AbstractArray{#T<:Base.Dates.TimeType, N<:Any}) at dates/arithmetic.jl:104.
To fix, define 
    -(Base.Range{#T<:Base.Dates.TimeType}, DataArrays.AbstractDataArray{#T<:Base.Dates.TimeType, N<:Any})
before the new definition.
Warning: New definition 
    -(DataArrays.AbstractDataArray, AbstractArray) at /Users/jiahao/.julia/v0.4/DataArrays/src/operators.jl:349
is ambiguous with: 
    -(AbstractArray{#T<:Base.Dates.TimeType, N<:Any}, Base.Range{#T<:Base.Dates.TimeType}) at dates/arithmetic.jl:103.
To fix, define 
    -(DataArrays.AbstractDataArray{#T<:Base.Dates.TimeType, N<:Any}, Base.Range{#T<:Base.Dates.TimeType})
before the new definition.
Warning: New definition 
    -(DataArrays.AbstractDataArray, AbstractArray) at /Users/jiahao/.julia/v0.4/DataArrays/src/operators.jl:349
is ambiguous with: 
    -(AbstractArray{#T<:Base.Dates.TimeType, N<:Any}, Union{DenseArray{#P<:Union{Base.Dates.CompoundPeriod, Base.Dates.Period}, N<:Any}, Base.SubArray{#P<:Union{Base.Dates.CompoundPeriod, Base.Dates.Period}, N<:Any, A<:DenseArray, I<:Tuple{Vararg{Union{Int64, Base.Range{Int64}, Base.Colon}}}, LD<:Any}}) at dates/arithmetic.jl:88.
To fix, define 
    -(DataArrays.AbstractDataArray{#T<:Base.Dates.TimeType, N<:Any}, Union{DenseArray{#P<:Union{Base.Dates.CompoundPeriod, Base.Dates.Period}, N<:Any}, Base.SubArray{#P<:Union{Base.Dates.CompoundPeriod, Base.Dates.Period}, N<:Any, A<:DenseArray, I<:Tuple{Vararg{Union{Int64, Base.Range{Int64}, Base.Colon}}}, LD<:Any}})
before the new definition.
Warning: New definition 
    -(DataArrays.AbstractDataArray, AbstractArray) at /Users/jiahao/.julia/v0.4/DataArrays/src/operators.jl:349
is ambiguous with: 
    -(AbstractArray{#T<:Base.Dates.TimeType, N<:Any}, AbstractArray{#T<:Base.Dates.TimeType, N<:Any}) at dates/arithmetic.jl:105.
To fix, define 
    -(DataArrays.AbstractDataArray{#T<:Base.Dates.TimeType, N<:Any}, AbstractArray{#T<:Base.Dates.TimeType, N<:Any})
before the new definition.
Warning: New definition 
    -(AbstractArray, DataArrays.AbstractDataArray) at /Users/jiahao/.julia/v0.4/DataArrays/src/operators.jl:349
is ambiguous with: 
    -(Union{DenseArray{#P<:Union{Base.Dates.CompoundPeriod, Base.Dates.Period}, N<:Any}, Base.SubArray{#P<:Union{Base.Dates.CompoundPeriod, Base.Dates.Period}, N<:Any, A<:DenseArray, I<:Tuple{Vararg{Union{Int64, Base.Range{Int64}, Base.Colon}}}, LD<:Any}}, AbstractArray{#T<:Base.Dates.TimeType, N<:Any}) at dates/arithmetic.jl:90.
To fix, define 
    -(Union{DenseArray{#P<:Union{Base.Dates.CompoundPeriod, Base.Dates.Period}, N<:Any}, Base.SubArray{#P<:Union{Base.Dates.CompoundPeriod, Base.Dates.Period}, N<:Any, A<:DenseArray, I<:Tuple{Vararg{Union{Int64, Base.Range{Int64}, Base.Colon}}}, LD<:Any}}, DataArrays.AbstractDataArray{#T<:Base.Dates.TimeType, N<:Any})
before the new definition.
Warning: New definition 
    -(AbstractArray, DataArrays.AbstractDataArray) at /Users/jiahao/.julia/v0.4/DataArrays/src/operators.jl:349
is ambiguous with: 
    -(Base.Range{#T<:Base.Dates.TimeType}, AbstractArray{#T<:Base.Dates.TimeType, N<:Any}) at dates/arithmetic.jl:104.
To fix, define 
    -(Base.Range{#T<:Base.Dates.TimeType}, DataArrays.AbstractDataArray{#T<:Base.Dates.TimeType, N<:Any})
before the new definition.
Warning: New definition 
    -(AbstractArray, DataArrays.AbstractDataArray) at /Users/jiahao/.julia/v0.4/DataArrays/src/operators.jl:349
is ambiguous with: 
    -(AbstractArray{#T<:Base.Dates.TimeType, N<:Any}, AbstractArray{#T<:Base.Dates.TimeType, N<:Any}) at dates/arithmetic.jl:105.
To fix, define 
    -(AbstractArray{#T<:Base.Dates.TimeType, N<:Any}, DataArrays.AbstractDataArray{#T<:Base.Dates.TimeType, N<:Any})
before the new definition.

@GordStephen
Copy link
Contributor Author

Yikes! Well, I guess the good news is that the errors all seem to trace back to just two method definitions (lines 326/349 in DataArrays/src/operators.jl). I'll go open an issue at DataArrays and see what I can do about it - or do you think there's something that could be done on this end to reduce the impact more generally?

@timholy
Copy link
Member

timholy commented Jul 18, 2015

The deprecationsambiguities also affect Images.

I wonder if it's worth at least a little time seeing if we can fix this more generally. Assuming you don't want to make a Dates.TimeType into a subtype of Number, I wonder if we should introduce an AbstractScalar type? And then we could generalize the definitions in arraymath.jl, delete the time-specific methods, and then package authors only have one place they have to worry about in terms of ambiguities.

@GordStephen
Copy link
Contributor Author

I like the sound of that - one thing to watch for would be the fact that TimeType/Period/CompoundPeriod operations often produce results that are typed differently than their operands, which I've found to be tricky to deal with very generally. But a general solution would definitely be preferable - right now defining date array methods is like fighting some sort of hydra - fixing one ambiguity usually creates a bunch more!

@timholy
Copy link
Member

timholy commented Jul 23, 2015

After working on this for a few hours, I don't think we can have a generic fix without addressing #8027. The specific place this comes up in Dates is in adding a CompoundPeriod to a Period, which involves concatenation and hence should promote two Periods to Period; however, falling back on generic AbstractArray operations for A+b leads one to wish for a promotion rule that selects CompoundPeriod.

Now here's my provocative question: is the current slew of ambiguity warnings in packages worth the benefit of this PR? Or should we revert it?

@GordStephen
Copy link
Contributor Author

@timholy, thanks for all the work to try to fix the underlying issues here! Maybe the solution for now is to move the functionality into a standalone module, so the few who need it right now (maybe just me?) can have it without causing broader package issues.

@timholy
Copy link
Member

timholy commented Jul 24, 2015

Let's hold out for a bit more and see whether #12292 wraps up soon. Certainly it would be great to support the operations you've supported.

If the answer on #12292 is "just can't fix this now," I confess I like your solution. I hate the idea of backing out excellent work, especially from a new contributor. But to me it seems like the only workable choice. Your flexibility gains a big 💯 from me, and I hope to see you around more!

@GordStephen
Copy link
Contributor Author

Ok, sounds good!

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.

Inconsistent support for array operations with TimeType/Period values
5 participants