-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Description
When you write:
x[idx] .= z
it is processed as:
Base.materialize!(Base.dotview(x, idx), Base.broadcasted(Base.identity, z))
which allows packages to give a special meaning toBase.dotview(x, idx), which is important if they want to define types that are broadcasting aware (as it allows to specialize the behavior of dotview).
On the other hand:
x.field .= z
is processed as:
Base.materialize!(Base.getproperty(x, :field), Base.broadcasted(Base.identity, z))
which does not allow to introduce a special broadcasting behavior in this case, as we call just getproperty (this is as if we called getindex instead of dotview in the first example).
The solution would be to use some intermediate function (name is tentative) with a defualt definition:
maybegetproperty(x, y) = getproperty(x, y)
that could get a special implementation in packages if needed.
A concrete use case is in DataFrames.jl, which allows:
df[:, :newcol] .= 1
to add a new column to the df DataFrame, while:
df.newcol .= 1
errors if :newcol does not exist in df.
@tkf you had a more more general idea what could be done here. Can you please comment on this?