-
Notifications
You must be signed in to change notification settings - Fork 7
Add a no-op constructor when DataValue is called on itself. #48
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
base: master
Are you sure you want to change the base?
Conversation
I don't understand this. Why do we need this? |
It's just a no-op constructor; so if someone does |
If you don't want to define this for whatever reason, just let me know; I can define a work-around on Tables.jl side. |
FWIW we had to define the same constructor in CategoricalArrays for this reason. |
I'm not aware of what a better solution would be: we want to ensure we have an instance of a type that we know beforehand. For |
I think we are still used to constructors automatically falling back to |
So shouldn't we just use The semantics of the On the other hand, the semantics of |
Yeah, maybe. I don't understand that code TBH. Where is the constructor called? |
Haha, I was also pretty lost in that code :) |
Given a NamedTuple like NamedTuple{(:a, :b, :c)}( (Int64(input.a), Float64(intput.b), DataValue{String}(input.c)) )
julia> DataValue{String}(missing)
DataValue{String}()
julia> convert(DataValue{String}, missing)
ERROR: MethodError: Cannot `convert` an object of type Missing to an object of type String
Closest candidates are:
convert(::Type{T<:AbstractString}, ::T<:AbstractString) where T<:AbstractString at strings/basic.jl:207
convert(::Type{T<:AbstractString}, ::AbstractString) where T<:AbstractString at strings/basic.jl:208
convert(::Type{T}, ::T) where T at essentials.jl:154
Stacktrace:
[1] convert(::Type{DataValue{String}}, ::Missing) at /Users/jacobquinn/.julia/packages/DataValues/SNSrX/src/scalar/core.jl:25
[2] top-level scope at none:0 which is why I think I originally went with the constructor call. @davidanthoff , would you be ok defining |
Yes, that seems like the right way to do this. Side question: why does this syntax actually work? It seems it does, but I would have expected that one needs to write this as |
Oh, does that syntax work? I wouldn't expect it to; just a typo by me! |
Ah, no, it doesn't work. I somehow mixed up the order in which I tried things :) |
Ok, updated this PR to define |
There seems to be a method ambiguity problem. Maybe if you define it as
that won't be the case? Not entirely clear to me why we are getting this error... How are you going to handle this on the Tables.jl side? Given that this is loaded behind a |
Good points David. In lieu of dealing w/ the complications of Requires.jl versioning, I think the approach here should work for now. It's not the most elegant, but the alternatives don't seem to offer anything much cleaner. Should we close this then? Or try to fix the ambiguity? |
Yeah, I think your PR over at Tables.jl is probably the easiest path forward. I think we should probably still add the |
Fixes JuliaData/Tables.jl#25