Code Monkey home page Code Monkey logo

Comments (8)

mkborregaard avatar mkborregaard commented on August 12, 2024 1

I like the interpolation, I don't think we need consistency with DataFramesMeta on this.

from statsplots.jl.

piever avatar piever commented on August 12, 2024

What is missing is that macro are called before the code is executed, so the macro cannot know that x will be a symbol. @df is inspired by DataFramesMeta's @with (see here) and distinguishes symbols syntactically and cannot know that x will be a symbol at parse time. If you think this application is common enough, I can maybe implement the _I_(expr) notation (as they do in @with). like:

x = :A
@df smallDf histogram(_I_(x))

But honestly I'm not a huge fan of this syntax. Maybe:

x = :A
@df smallDf histogram($x)

would make more sense? It seems more intuitive to me, not sure why DataFramesMeta went with _I_(expr) which is a bit awkward to type.

from statsplots.jl.

romainFr avatar romainFr commented on August 12, 2024

Thanks ! Of course that makes sense. I encountered it while changing some old code that was using the deprecated syntax plot(smallDf,x). I think that might be a nice feature to add if more people agree -- as for the syntax, I guess being coherent with DataFrameMeta is a good thing.

from statsplots.jl.

piever avatar piever commented on August 12, 2024

@mkborregaard what's your take for a syntax that allows "interpolating" symbols in a @df call? _I_(expr) like DataFramesMeta, $expr (which is what I would try as a user) or yet another thing?

from statsplots.jl.

piever avatar piever commented on August 12, 2024

I actually started wondering whether we should just always use cols instead. Now we have cols(v::AbstractArray{Int64}) mean the hcat of those columns, but maybe we could also have cols(v::AbstractArray{Symbol}) to select the columns by name, as well as a cols(v::Int64) or cols(v::Symbol) if it's just one column but we want to choose it by index rather than name, or we want to chose it by name but the name is a variable. Maybe the 1 column version could be renamed col, though I probably prefer to just have one function with different methods for ints/symbols and arrays of ints/symbols.

The rule would be:

  • If it's a symol that you type, use the symbol
  • otherwise, use cols to signal to the macro that the content represent one or more columns

from statsplots.jl.

mkborregaard avatar mkborregaard commented on August 12, 2024

I think that suggestion has the advantage that the interpolation after a macro feels a little magical, and enough slightly differing uses of $ after a macro (i.e. the suggested use is different from that used in BenchmarkTools) could create slightly fuzzy interface. Though cols is clearly ours, and at the cost of being slightly clumsy and wordy should be quite clear to understand.

from statsplots.jl.

piever avatar piever commented on August 12, 2024

@romainFr If you want you can try #120 and see if it addresses your use case.

from statsplots.jl.

romainFr avatar romainFr commented on August 12, 2024

@piever It does, thanks !

from statsplots.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.