-
Notifications
You must be signed in to change notification settings - Fork 55
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
Easier syntax for mixed computations by row or by column #186
Comments
Thanks for this! I appreciate the proposal. I think this idea conflicts with other appearances of
means that
This is not what's going on with the Note that in DataFramesMeta, both the release branch and
You are right that the |
I do know that the broadcasted assignment syntax is usually understood as mutation of an array, I just felt that for a macro which defines a nonstandard DSL for DataFrame manipulation, such a nonstandard functionality is ok. I actually have the situation quite often that I have an expression that is not really suitable for broadcasting syntax. For example, keywords don't broadcast, so if you want to pass values of one column as keyword arguments to a function, that wouldn't work unless you manually created the map that I proposed here. Do you think that's too uncommon to make it easy with this dot assignment syntax? |
I think that this is a slightly different mental of DataFramesMeta than I am imagining people to have. I think I would like people to view DataFramesMeta as a way to construct an expression for inputting into |
Maybe you're right, I didn't even know about the @transform(df,
@byrow y = f(:x),
z = g.(:x))
# or
@transform(df,
y = @byrow f(:x),
z = g.(:x))
I understand where you're coming from. Personally, I value non-redundant syntax a lot, especially for things that I have to write over and over. So to me, a package like DataFramesMeta really makes DataFrames comfortable to use, because DataFrames' defaults rely on a lot of redundant typing. Which is fine, because it's understandable that the base package doesn't want to use macros. But I'd also say that this frees macro packages which try to implement the smoothest DSL workflow possible from staying too close to the original syntax. In my mind it's not a problem to do a |
Interesting. Another thing that does not work with your proposal is that it cannot be extended to expressions that do no create a new variable (which may happen in |
Using
Unfortunately |
Ok, I thought it might be possible since `@.` exists, but I did not look
into it.
…On Thu, Oct 15, 2020 at 5:29 AM Milan Bouchet-Valat < ***@***.***> wrote:
Using .= is appealing, but in Julia one needs to use dots elsewhere in
the expression to enable broadcasting, e.g. y .= x .+ 1. So that would
essentially be a syntax pun.
But I like the idea: maybe a related one would be to use the syntax
@Transform., @select., etc.
Unfortunately @select. isn't a valid identifier name so it can't work.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#186 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABPPPXNLUYRVBRBJSOVZA5TSK3TLHANCNFSM4SHAITAQ>
.
|
Closed with the addition of |
I came up with a syntax that I like quite a lot in my own little macro package I was trying out, and I wanted to see if there is interest to add something like it here.
The problem
Some computations in
@transform
,@combine
, etc. are easier to express when thinking about the inputs as whole column vectors. Others are easier to write in an elementwise fashion. Currently, computations are done on whole vectors. There is a@byrow
macro but I think that iterates over all rows, making it slower than what I have in mind. In any case, it can not be mixed with the vector style.The solution
We can pun on broadcasting assignment syntax to solve this issue. Here is an example:
How it works
While the default syntax creates a this function:
The rowwise version creates this:
This should still be as fast as possible for a row wise computation, compared to iterating all rows unnecessarily.
Another benefit is that the two syntaxes can be easily mixed, depending on which way of thinking is more appropriate for the current computation.
The text was updated successfully, but these errors were encountered: