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

Support parse(type, str) in @mutete and @transmute #42

Closed
takuizum opened this issue Sep 4, 2023 · 3 comments
Closed

Support parse(type, str) in @mutete and @transmute #42

takuizum opened this issue Sep 4, 2023 · 3 comments

Comments

@takuizum
Copy link

takuizum commented Sep 4, 2023

Hi all,

@mutate and @transmute cannot recognize a function's arguments correctly.
For example, the parse(type, str) function converts the string to another type, but @mutate recognizes the first argument, which is a target type, as the variable in the data frame.

The following code returns ERROR: ArgumentError: column name :Int64 not found in the data frame

df = DataFrame(A = ["1", "2"])
@mutate(df, B = parse(Int64, A))
@takuizum
Copy link
Author

takuizum commented Sep 4, 2023

as_integer can parse string as integer.

@takuizum takuizum closed this as completed Sep 4, 2023
@kdpsingh kdpsingh reopened this Sep 4, 2023
@kdpsingh
Copy link
Member

kdpsingh commented Sep 4, 2023

The original code doesn't work because Tidier looks for a column named Int64.

The following code uses interpolation to let Tidier know that Int64 is coming from the global environment and should work (though I haven't tested to confirm).

@mutate(df, B = parse(!!Int64, A))

However, I would like to fix this behavior so that keywords like Int64 and true/false don't require interpolation. I'll leave this issue open until we fix it.

@kdpsingh
Copy link
Member

This is now fixed in #69. Here is the output from the fixed version:

julia> df = DataFrame(A = ["1", "2"])
2×1 DataFrame
 Row │ A      
     │ String 
─────┼────────
   11
   22

julia> @mutate(df, B = parse(Int64, A))
2×2 DataFrame
 Row │ A       B     
     │ String  Int64 
─────┼───────────────
   11           1
   22           2

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