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

by with arrays of inputs and broadcasting #1615

Closed
pdeffebach opened this issue Dec 3, 2018 · 5 comments
Closed

by with arrays of inputs and broadcasting #1615

pdeffebach opened this issue Dec 3, 2018 · 5 comments
Labels

Comments

@pdeffebach
Copy link
Contributor

It looks like the splatting doesn't quite work with having vectors of columns you want to act on.

using Statistics
df = DataFrame(x = repeat(1:2, 5), a=rand(10), b=rand(10));
by(df, :x, [:a, :b] .=> mean, :b => std) # doesn't work
#=
ERROR: MethodError: no method matching by(::DataFrame, ::Symbol, ::Array{Pair{Symbol,typeof(mean)},1}, ::Pair{Symbol,typeof(std)})
=#
by(df, :x, :a => mean, :b => std) # works

I'm done with grad apps now so I will see if I can poke around for a fix soon.

@nalimilan
Copy link
Member

I guess this could be handled by merging the vectors/tuples/pairs.

@bkamins
Copy link
Member

bkamins commented Dec 4, 2018

I thought that this was intentional, but we can add merging as @nalimilan writes. The rules would be to merge:

  • with positional arguments:
    • Pairs and Tuples of Pairs into a single Tuple (this is pretty clear that it should be allowed and is simple)
    • several NamedTuples of Pairs into a single NamedTuple (this is pretty clear that it should be allowed and is simple)
  • with keyword arguments: here it is problematic as we would have to allow mixing positional and keyword arguments (this will be more involved to get it fully right as there are many possible problematic combinations to safeguard against) - @pdeffebach is there a need to handle this case?

@bkamins bkamins mentioned this issue Dec 4, 2018
8 tasks
@pdeffebach
Copy link
Contributor Author

I agree that named-tuple for broadcasted arguments is not necessary. But I think that this should be allowed.

Yes I think merging should do the trick, we can discuss more in depth once I make a PR/

@bkamins
Copy link
Member

bkamins commented Dec 4, 2018

@pdeffebach When you write a PR please take this behavior into account:

julia> merge((a=1, b=2), (b=10, c=20))
(a = 1, b = 10, c = 20)

so duplicates are silently overwritten. We do not want this I think and an error should be thrown in case of a duplicate.

@bkamins
Copy link
Member

bkamins commented Apr 4, 2020

This is done, so I am closing this. We are missing All, Not and Between broadcasting, but this is a separate issue (the mechanics is there). If you feel something needs to ba added here please reopen.

@bkamins bkamins closed this as completed Apr 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants