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

Creating new macros #80

Closed
JockLawrie opened this issue Dec 1, 2017 · 2 comments
Closed

Creating new macros #80

JockLawrie opened this issue Dec 1, 2017 · 2 comments

Comments

@JockLawrie
Copy link

Hi there,

I am creating some new macros for use with the @linq macro. I can create the macros, but I can't get @linq to recognize them. Simple example below. Any ideas?

using DataFrames
using DataFramesMeta

# simple renaming of where macro
macro selectrows(d, args...)
    esc(DataFramesMeta.where_helper(d, args...))
end

function linq(::DataFramesMeta.SymbolParameter{:selectrows}, d, args...)
    DataFramesMeta.where_helper(d, args...)
end

df = DataFrame(x = 1:3, y = [2, 1, 2]);
@linq df |> @selectrows(:x .> 1)    # OK
@linq df |> selectrows(:x .> 1)     # Error

The error is:

ERROR: MethodError: no method matching isless(::Int64, ::Symbol)
Closest candidates are:
  isless(::Symbol, ::Symbol) at strings/basic.jl:136
  isless(::DataArrays.NAtype, ::Any) at /home/jock/.julia/v0.6/DataArrays/src/operators.jl:383
  isless(::Real, ::AbstractFloat) at operators.jl:97
  ...
Stacktrace:
 [1] (::##97#98)(::Symbol) at ./<missing>:0
 [2] broadcast(::Function, ::Symbol) at ./broadcast.jl:434
@tshort
Copy link
Contributor

tshort commented Dec 1, 2017

I'm not at a computer to try it, but I think you need to define that linq method as DataFramesMeta.linq.

@JockLawrie
Copy link
Author

Ah, yes that did it, thanks.

FYI - I'm mostly just renaming some macros so that I can remember what I did 6 months later. I have:

  • selectcols (renamed from select)
  • selectrows (renamed from where)
  • appendcols! (renamed from transform and check that column names do not already exist)
  • mutatecols! (renamed from transform and check that column names already exist)
  • orderby and by unchanged

Thanks again.

@tshort tshort closed this as completed Dec 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants