Skip to content
This repository has been archived by the owner on May 4, 2019. It is now read-only.

Base.Dates ambiguity errors for array addition/subtraction #158

Closed
GordStephen opened this issue Jul 14, 2015 · 2 comments
Closed

Base.Dates ambiguity errors for array addition/subtraction #158

GordStephen opened this issue Jul 14, 2015 · 2 comments

Comments

@GordStephen
Copy link

As noted by @jiahao in JuliaLang/julia#12115 (comment), JuliaLang/julia@79a2add extends Base.Dates.TimeType and Base.Dates.Period/Base.Dates.CompoundPeriod array operations, which results in new ambiguity errors for DataArray + and - methods:

julia> using DataArrays
Warning: New definition 
    +(AbstractArray, DataArrays.DataArray) at /home/gord/.julia/v0.4/DataArrays/src/operators.jl:326
is ambiguous with: 
    +(Union{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}, DenseArray{#P<:Union{Base.Dates.CompoundPeriod, Base.Dates.Period}, N<:Any}}, AbstractArray{#T<:Base.Dates.TimeType, N<:Any}) at dates/arithmetic.jl:90.
To fix, define 
    +(Union{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}, DenseArray{#P<:Union{Base.Dates.CompoundPeriod, Base.Dates.Period}, N<:Any}}, DataArrays.DataArray{#T<:Base.Dates.TimeType, N<:Any})
before the new definition.
Warning: New definition 
    +(AbstractArray, DataArrays.AbstractDataArray) at /home/gord/.julia/v0.4/DataArrays/src/operators.jl:349
is ambiguous with: 
    +(Union{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}, DenseArray{#P<:Union{Base.Dates.CompoundPeriod, Base.Dates.Period}, N<:Any}}, AbstractArray{#T<:Base.Dates.TimeType, N<:Any}) at dates/arithmetic.jl:90.
To fix, define 
    +(Union{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}, DenseArray{#P<:Union{Base.Dates.CompoundPeriod, Base.Dates.Period}, N<:Any}}, DataArrays.AbstractDataArray{#T<:Base.Dates.TimeType, N<:Any})
before the new definition.
Warning: New definition 
    -(Base.Range, DataArrays.DataArray) at /home/gord/.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 /home/gord/.julia/v0.4/DataArrays/src/operators.jl:326
is ambiguous with: 
    -(Union{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}, DenseArray{#P<:Union{Base.Dates.CompoundPeriod, Base.Dates.Period}, N<:Any}}, AbstractArray{#T<:Base.Dates.TimeType, N<:Any}) at dates/arithmetic.jl:90.
To fix, define 
    -(Union{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}, DenseArray{#P<:Union{Base.Dates.CompoundPeriod, Base.Dates.Period}, N<:Any}}, DataArrays.DataArray{#T<:Base.Dates.TimeType, N<:Any})
before the new definition.
Warning: New definition 
    -(AbstractArray, DataArrays.DataArray) at /home/gord/.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 /home/gord/.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 /home/gord/.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 /home/gord/.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 /home/gord/.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 /home/gord/.julia/v0.4/DataArrays/src/operators.jl:349
is ambiguous with: 
    -(AbstractArray{#T<:Base.Dates.TimeType, N<:Any}, Union{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}, DenseArray{#P<:Union{Base.Dates.CompoundPeriod, Base.Dates.Period}, N<:Any}}) at dates/arithmetic.jl:88.
To fix, define 
    -(DataArrays.AbstractDataArray{#T<:Base.Dates.TimeType, N<:Any}, Union{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}, DenseArray{#P<:Union{Base.Dates.CompoundPeriod, Base.Dates.Period}, N<:Any}})
before the new definition.
Warning: New definition 
    -(DataArrays.AbstractDataArray, AbstractArray) at /home/gord/.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 /home/gord/.julia/v0.4/DataArrays/src/operators.jl:349
is ambiguous with: 
    -(Union{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}, DenseArray{#P<:Union{Base.Dates.CompoundPeriod, Base.Dates.Period}, N<:Any}}, AbstractArray{#T<:Base.Dates.TimeType, N<:Any}) at dates/arithmetic.jl:90.
To fix, define 
    -(Union{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}, DenseArray{#P<:Union{Base.Dates.CompoundPeriod, Base.Dates.Period}, N<:Any}}, DataArrays.AbstractDataArray{#T<:Base.Dates.TimeType, N<:Any})
before the new definition.
Warning: New definition 
    -(AbstractArray, DataArrays.AbstractDataArray) at /home/gord/.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 /home/gord/.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
Author

If you're working off of a recent unstable master of Base (and don't actually need support for adding/subtracting DataArray{Date}, etc) , pasting this in to the top of src/operators.jl will at least eliminate the ambiguity errors:

dats = (:DataArray, :AbstractDataArray)
for op in (:+, :-)
  for dat1 in dats
    for dat2 in dats
      @eval begin
        ($op){P<:Base.Dates.GeneralPeriod, Q<:Base.Dates.GeneralPeriod}(x::$dat1{P}, y::$dat2{Q}) = throw(MethodError)
        ($op){P<:Base.Dates.GeneralPeriod, T<:Base.Dates.TimeType}(x::$dat1{P}, y::$dat2{T}) = throw(MethodError)
        ($op){T<:Base.Dates.TimeType, P<:Base.Dates.GeneralPeriod}(x::$dat1{T}, y::$dat2{P}) = throw(MethodError)
        ($op){T<:Base.Dates.TimeType}(x::$dat1{T}, y::$dat2{T}) = throw(MethodError) 
      end #eval
    end #for

    @eval begin
      ($op){P<:Base.Dates.GeneralPeriod, Q<:Base.Dates.GeneralPeriod}(x::StridedArray{P}, y::$dat1{Q}) = throw(MethodError)
      ($op){P<:Base.Dates.GeneralPeriod, Q<:Base.Dates.GeneralPeriod}(x::$dat1{Q}, y::StridedArray{P}) = throw(MethodError)
      ($op){P<:Base.Dates.GeneralPeriod, T<:Base.Dates.TimeType}(x::StridedArray{P}, y::$dat1{T}) = throw(MethodError)
      ($op){T<:Base.Dates.TimeType, P<:Base.Dates.GeneralPeriod}(x::$dat1{T}, y::StridedArray{P}) = throw(MethodError)

      ($op){T<:Base.Dates.TimeType, P<:Base.Dates.GeneralPeriod}(x::Range{T}, y::$dat1{P}) = throw(MethodError) 
      ($op){P<:Base.Dates.GeneralPeriod, T<:Base.Dates.TimeType}(x::$dat1{P}, y::Range{T}) = throw(MethodError) 
      ($op){T<:Base.Dates.TimeType, P<:Base.Dates.GeneralPeriod}(x::AbstractArray{T}, y::$dat1{P}) = throw(MethodError) 
      ($op){P<:Base.Dates.GeneralPeriod, T<:Base.Dates.TimeType}(x::$dat1{P}, y::AbstractArray{T}) = throw(MethodError) 

      ($op){T<:Base.Dates.TimeType, U<:Base.Dates.TimeType}(x::Range{T}, y::$dat1{U}) = throw(MethodError) 
      ($op){T<:Base.Dates.TimeType, U<:Base.Dates.TimeType}(x::$dat1{T}, y::Range{U}) = throw(MethodError) 
      ($op){T<:Base.Dates.TimeType}(x::Range{T}, y::$dat1{T}) = throw(MethodError) 
      ($op){T<:Base.Dates.TimeType}(x::$dat1{T}, y::Range{T}) = throw(MethodError) 
      ($op){T<:Base.Dates.TimeType}(x::AbstractArray{T}, y::$dat1{T}) = throw(MethodError) 
      ($op){T<:Base.Dates.TimeType}(x::$dat1{T}, y::AbstractArray{T}) = throw(MethodError) 
    end #eval
  end #for
end #for

@GordStephen
Copy link
Author

JuliaLang/julia#12370 fixed this upstream.

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

No branches or pull requests

1 participant