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

compatibility with DataFrames mini-language #4

Open
tbeason opened this issue Nov 22, 2021 · 6 comments · May be fixed by #5
Open

compatibility with DataFrames mini-language #4

tbeason opened this issue Nov 22, 2021 · 6 comments · May be fixed by #5

Comments

@tbeason
Copy link

tbeason commented Nov 22, 2021

I use @chain from Chain.jl quite a bit, but it doesn't seem like @mfalse plays nicely with it. Do you know if it might be possible to get them to work well together?

@pdeffebach
Copy link
Owner

Can you show an MWE?

@tbeason
Copy link
Author

tbeason commented Nov 22, 2021

Welp, perhaps it isn't about @chain at all! Does @mfalse not always work with filter?

Setup:

julia> using DataFrames, Chain, MissingsAsFalse

julia> df = DataFrame(x=rand(4),inds = [true, false, true, missing])
4×2 DataFrame
 Row │ x          inds
     │ Float64    Bool?
─────┼────────────────────
   10.392307      true
   20.20751      false
   30.940361      true
   40.0766065  missing

The actual problem:

julia> @mfalse filter("inds" => ==(true),df)
ERROR: TypeError: non-boolean (Missing) used in boolean context
...

julia> @mfalse df.inds.==true
4-element BitVector:
 1
 0
 1
 0

# I guess this works!?
julia> @mfalse filter(r -> r.inds==true,df)
2×2 DataFrame
 Row │ x         inds
     │ Float64   Bool?
─────┼─────────────────
   10.392307   true
   20.940361   true

What I want to actually do (which doesn't work)

# option 1 (preferred!)
@chain df begin
       @mfalse filter("inds" => ==(true),_)
       end

# option 2
@mfalse @chain df begin
       filter("inds" => ==(true),_)
       end

@tbeason
Copy link
Author

tbeason commented Nov 22, 2021

Yes clearly now this is definitely about filter and not about @chain. Changing the issue title.

julia> @chain df begin
       @mfalse filter(r-> r.inds ==(true),_)
       end
2×2 DataFrame
 Row │ x         inds
     │ Float64   Bool?
─────┼─────────────────
   10.392307   true
   20.940361   true

@tbeason tbeason changed the title work with piping macros? compatibility with DataFrames mini-language Nov 22, 2021
@pdeffebach
Copy link
Owner

The problem is with ==(true). @mfalse isn't looking for the use of ==(true) in that way. I can add something that fixes it.

@pdeffebach pdeffebach linked a pull request Dec 6, 2021 that will close this issue
@pdeffebach
Copy link
Owner

@tbeason I have created a PR to fix this in #5 . Do you want to review?

@tbeason
Copy link
Author

tbeason commented Dec 6, 2021

gonna be a few days, it's the end of the semester you know! I'm also quite unskilled in macro wizardry but perhaps that won't be necessary for review

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

Successfully merging a pull request may close this issue.

2 participants