-
Notifications
You must be signed in to change notification settings - Fork 2
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
Support convert
on Row
#27
Conversation
Base.convert(::Type{Row{S}}, fields) where {S} = Row(S(), fields) | ||
Base.convert(::Type{Row{S}}, fields::Row) where {S} = Row(S(), fields) # Dispatch ambiguity fix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Base.convert(::Type{Row{S}}, fields) where {S} = Row(S(), fields) | |
Base.convert(::Type{Row{S}}, fields::Row) where {S} = Row(S(), fields) # Dispatch ambiguity fix | |
Base.convert(::Type{Row{S}}, fields) where {S} = Row(S(), fields) | |
Base.convert(::Type{Row{S}}, fields::Row) where {S} = Row(S(), fields) # Dispatch ambiguity fix | |
Base.convert(::Type{Row{S}}, fields::Row{S}) where {S} = fields |
this might be overly defensive, but I have too many battle scars tracking down performance issues to implicit no-op conversions that accidentally dispatch to a copy-triggering method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually this brings up a philosophical issue; Row
construction is not necessarily idempotent for any given schema.
So there's a choice here of whether we want to actually make conversion semantics the same as construction semantics
This makes me think we shouldn't merge this; the caller should be required to make these kinds of choices/drive this behavior explicitly.
In other words, I think in the example in the OP the caller should explicitly push!(signals, Signal(nt))
; depending on the situation the error that gets raised otherwise is actually "a feature" and not just an inconvenience depending on the caller's actual intentions, so we should continue to force them to express those intentions explicitly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in the example in the OP the caller should explicitly
push!(signals, Signal(nt))
; depending on the situation the error that gets raised otherwise is actually "a feature" and not just an inconvenience depending on the caller's actual intentions, so we should continue to force them to express those intentions explicitly
In that case I'd advocate for defining convert
and having it raise an error message explaining that intent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, I'd support that
@@ -171,6 +171,9 @@ Row(schema::Schema, fields) = Row(schema, NamedTuple(Tables.Row(fields))) | |||
Row(schema::Schema, fields::Row) = Row(schema, getfield(fields, :fields)) | |||
Row(schema::Schema, fields::NamedTuple) = Row(schema; fields...) | |||
|
|||
Base.convert(::Type{Row{S}}, fields) where {S} = Row(S(), fields) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we find it weird to support convert(::Type{Row{S}}, ...)
but not convert(::Type{<:Row{S}}, ...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. I think with the current inner constructor this could be tricky. I'll give this some thought
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! I wonder about the semantics of the transforms. E.g. with weird/wild transformations like
Line 25 in c7e0b13
b::String = string(a, b, c), |
should they trigger here? Or if we are
convert
ing, should we expect the thing we are converting already had those transformations applied but just lost it's type tag somewhere?
I think it could be useful to add something to the tour to show off this behavior so at least it's documented which way it works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'm against adding this ref https://github.com/beacon-biosignals/Legolas.jl/pull/27/files#r739363377
closing as stale, will open an issue for the action item here: #27 (comment) |
MWE of the original issue encountered which this PR addresses: