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

ambigous method error on missings #40

Open
bgctw opened this issue Feb 12, 2021 · 3 comments
Open

ambigous method error on missings #40

bgctw opened this issue Feb 12, 2021 · 3 comments
Assignees

Comments

@bgctw
Copy link

bgctw commented Feb 12, 2021

The following code converts from an Vector{Tuple} to a Vector of first entry of the Tuple. I expected that I can access it like a Vector. However, currently it errors with 'method is ambiguous'. How can I make it work?

tvec = allowmissing([(rand(),rand()) for i=1:6]);
tvec[1] = missing
c = mappedarray(x-> ismissing(x) ? missing : first(x),tvec);
c[1:2]
@johnnychen94 johnnychen94 self-assigned this Feb 18, 2021
@timholy
Copy link
Member

timholy commented Feb 24, 2021

This would be fixed by #34.

@bgctw
Copy link
Author

bgctw commented Feb 25, 2021

Tested with version MasonProtter@3741807 mentioned in #34

On my Setup (Julia 1.6_RC1on Linux) it still fails:

julia> c[1:2]
ERROR: MethodError: convert(::Type{Union{}}, ::Float64) is ambiguous. Candidates:
  convert(::Type{T}, x::Number) where T<:Number in Base at number.jl:7
  convert(::Type{T}, x::Number) where T<:AbstractChar in Base at char.jl:179
  convert(::Type{C}, c::Number) where C<:Colorant in ColorTypes at /home/twutz/.julia/packages/ColorTypes/RF8lb/src/conversions.jl:74
  convert(::Type{Union{}}, x) in Base at essentials.jl:203
  convert(::Type{T}, arg) where T<:VecElement in Base at baseext.jl:8
  convert(::Type{T}, x) where T<:Observables.Observable in Observables at /home/twutz/.julia/packages/Observables/Yf3xU/src/Observables.jl:52
Possible fix, define
  convert(::Type{Union{}}, ::Number)

@bgctw
Copy link
Author

bgctw commented Mar 8, 2021

I tried to explicitly fix the return type of the function. But this does not work either.
(Julia 1.6_RC1, ca07b29)

tvec = allowmissing([(rand(),rand()) for i=1:6]);
tvec[1] = missing
function f1(x)::Union{Missing,Float64}
    ismissing(x) ? missing : first(x)
end
c = mappedarray(f1,tvec);
c[1:2]

Interestingly, in the stacktrace, MappedArrays.jl does not appear. Maybe the cause is at a different spot than type inference?

ERROR: MethodError: convert(::Type{Union{}}, ::Float64) is ambiguous. Candidates:
  convert(::Type{T}, x::Number) where T<:Number in Base at number.jl:7
  convert(::Type{T}, x::Number) where T<:AbstractChar in Base at char.jl:179
  convert(::Type{Union{}}, x) in Base at essentials.jl:203
  convert(::Type{T}, arg) where T<:VecElement in Base at baseext.jl:8
Possible fix, define
  convert(::Type{Union{}}, ::Number)
Stacktrace:
 [1] convert(#unused#::Type{Missing}, x::Float64)
   @ Base ./missing.jl:69
 [2] setindex!(A::Vector{Missing}, x::Float64, i1::Int64)
   @ Base ./array.jl:839
 [3] macro expansion
   @ ./multidimensional.jl:860 [inlined]
 [4] macro expansion
   @ ./cartesian.jl:64 [inlined]
 [5] _unsafe_getindex!
   @ ./multidimensional.jl:855 [inlined]
 [6] _unsafe_getindex(#unused#::IndexLinear, A::ReadonlyMappedArray{Missing, 1, Vector{Union{Missing, Tuple{Float64, Float64}}}, typeof(f1)}, I::UnitRange{Int64})
   @ Base ./multidimensional.jl:846
 [7] _getindex
   @ ./multidimensional.jl:832 [inlined]
 [8] getindex(A::ReadonlyMappedArray{Missing, 1, Vector{Union{Missing, Tuple{Float64, Float64}}}, typeof(f1)}, I::UnitRange{Int64})
   @ Base ./abstractarray.jl:1164
 [9] top-level scope
   @ REPL[201]:1

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

No branches or pull requests

3 participants