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

drop columns with nothing using @mutate? #116

Closed
mistermichaelll opened this issue Aug 31, 2024 · 2 comments
Closed

drop columns with nothing using @mutate? #116

mistermichaelll opened this issue Aug 31, 2024 · 2 comments

Comments

@mistermichaelll
Copy link

mistermichaelll commented Aug 31, 2024

More @mutate testing fun 😄 this is more of a behavior question rather than a bug.

In dplyr, you can drop columns using mutate by passing NULL. This is news to me, and I actually only learned this from tests from the source code.

For example:

library(dplyr)
df <- tibble(x = 1, y = 2)
df |> mutate(y = NULL)

#> # A tibble: 1 × 1
#>       x
#>   <dbl>
#> 1     1

In Tidier, I'd imagine that the closest behavior would be something like this:

using Tidier
using DataFrames
df = DataFrame(x = 1:3, y = 1:3)
@mutate(df, y = nothing)

But this doesn't drop the column, rather it just replaces y with a column of type nothing

3×2 DataFrame
 Row │ x      y       
     │ Int64  Nothing 
─────┼────────────────
   1 │     1          
   2 │     2          
   3 │     3          

Is dropping a column this way something that should be supported?

@kdpsingh
Copy link
Member

kdpsingh commented Sep 9, 2024

Thanks @mistermichaelll for surfacing this, and apologies for the delay in getting back to you.

I don't think we should support y = nothing as dropping the column. This is because of a fundamental difference between how nothing behaves in Julia and how NULL behaves in R.

In R, if you write x = c(1, NULL, 3), the result will be c(1, 3), whereas in Julia, x = [1, nothing, 3] will produce [1, nothing, 3]. Since nothing is a valid value, I don't think we should treat it the same as NULL in R.

@mistermichaelll
Copy link
Author

Makes total sense! I'll close this issue and remove this specific test from the mutate tests in #117

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