Giter VIP home page Giter VIP logo

Comments (6)

bkamins avatar bkamins commented on June 18, 2024

and return a NamedTuple.

The design is to:

  • return a NamedTuple if you do not want pseudo broadcasting;
  • return a DataFrame if you want it.

Example:

julia> df = DataFrame(id=repeat([1, 2], 5), val=1:10)
10×2 DataFrame
 Row │ id     val
     │ Int64  Int64
─────┼──────────────
   1 │     1      1
   2 │     2      2
   3 │     1      3
   4 │     2      4
   5 │     1      5
   6 │     2      6
   7 │     1      7
   8 │     2      8
   9 │     1      9
  10 │     2     10

julia> combine(groupby(df, :id), :val => (x -> (s=sum(x); DataFrame(total=s, frac=x ./ s))) => AsTable)
10×3 DataFrame
 Row │ id     total  frac
     │ Int64  Int64  Float64
─────┼─────────────────────────
   1 │     1     25  0.04
   2 │     1     25  0.12
   3 │     1     25  0.2
   4 │     1     25  0.28
   5 │     1     25  0.36
   6 │     2     30  0.0666667
   7 │     2     30  0.133333
   8 │     2     30  0.2
   9 │     2     30  0.266667
  10 │     2     30  0.333333

The question is how to reflect this in DataFramesMeta.jl.

from dataframes.jl.

pdeffebach avatar pdeffebach commented on June 18, 2024

Hmmm... I don't love the performance hit that would come with constructing a DataFrame. With the current implementation of the @astable macro-flag I would have to decide whether a DataFrame or a NamedTuple.

I wonder if it's best for DataFramesMeta.jl to do the broadcasting on their own.

However your response is a bit confusing

return a NamedTuple if you do not want pseudo broadcasting;

since currently returning (a = 1, b = [4, 5, 6]) throws an error. So it's not a broadcasting behavior you can opt in-or-out of.

from dataframes.jl.

bkamins avatar bkamins commented on June 18, 2024

throws an error.

Yes, because NamedTuple does not do broadcasting (as opposed to DataFrame)

from dataframes.jl.

bkamins avatar bkamins commented on June 18, 2024

Also I think that the performance hit, although noticeable, for most users would be a minor issue. The major issue, is, as you write, that @astable has to have only one meaning. Maybe @asdf or @asdataframe would be an alternative name?

from dataframes.jl.

pdeffebach avatar pdeffebach commented on June 18, 2024

Are there other advantages of making a DataFrame inside fun?

I don't really want to have to introduce both @astable and @asdataframe into the docs and tutorials if the only difference is the spreading behavior. I would just as soon do some spreading inside the anonymous function instead.

from dataframes.jl.

bkamins avatar bkamins commented on June 18, 2024

Are there other advantages of making a DataFrame inside fun?

I do not think so. The other would be making column names unique, but I guess it is not an issue in your case.

from dataframes.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.