paleolimbot edited a comment on pull request #11690:
URL: https://github.com/apache/arrow/pull/11690#issuecomment-977160148


   Ok...this has improved semantics for data.frame and better errors for tibble 
with respect to duplicate/missing names for columns.
   
   With data.frame input:
   
   <details>
   
   ``` r
   library(arrow, warn.conflicts = FALSE)
   library(dplyr, warn.conflicts = FALSE)
   
   df <- data.frame(a = 1)
   
   # "normal"
   df %>% mutate(df_col = tibble(a2 = a)) %>% collect()
   #> Warning in format.data.frame(if (omit) x[seq_len(n0), , drop = FALSE] 
else x, :
   #> corrupt data frame: columns will be truncated or padded with NAs
   #>   a            df_col
   #> 1 1 # A tibble: 1 × 1
   df %>% mutate(df_col = data.frame(a2 = a)) %>% collect()
   #>   a a2
   #> 1 1  1
   
   # duplicated cols
   df %>% mutate(df_col = tibble(a, a)) %>% collect()
   #> Error: Problem with `mutate()` column `df_col`.
   #> ℹ `df_col = tibble(a, a)`.
   #> x Column name `a` must not be duplicated.
   #> Use .name_repair to specify repair.
   df %>% mutate(df_col = data.frame(a, a)) %>% collect()
   #>   a df_col.a df_col.a.1
   #> 1 1        1          1
   df %>% mutate(df_col = data.frame(a, a, check.names = FALSE)) %>% collect()
   #>   a df_col.a df_col.a
   #> 1 1        1        1
   
   # empty names
   df %>% 
     mutate(df_col = data.frame(a, check.names = TRUE, fix.empty.names = TRUE)) 
%>% 
     collect()
   #>   a a
   #> 1 1 1
   df %>% 
     mutate(df_col = data.frame(a, check.names = TRUE, fix.empty.names = 
FALSE)) %>% 
     collect()
   #>   a  
   #> 1 1 1
   df %>% 
     mutate(df_col = data.frame(a, check.names = FALSE, fix.empty.names = 
TRUE)) %>% 
     collect()
   #>   a a
   #> 1 1 1
   df %>% 
     mutate(df_col = data.frame(a, check.names = FALSE, fix.empty.names = 
FALSE)) %>% 
     collect()
   #>   a  
   #> 1 1 1
   
   # ignored
   df %>% mutate(df_col = data.frame(a, check.rows = TRUE)) %>% collect()
   #>   a a
   #> 1 1 1
   df %>% mutate(df_col = data.frame(a, row.names = TRUE)) %>% collect()
   #>   a a
   #> 1 1 1
   ```
   
   </details>
   
   With record batch input:
   
   <details>
   
   ``` r
   library(arrow, warn.conflicts = FALSE)
   library(dplyr, warn.conflicts = FALSE)
   
   df <- record_batch(a = 1)
   
   # "normal"
   df %>% mutate(df_col = tibble(a2 = a)) %>% collect()
   #> Warning: Expression tibble(a2 = a) not supported in Arrow; pulling data 
into R
   #> # A tibble: 1 × 2
   #>       a df_col$a2
   #>   <dbl>     <dbl>
   #> 1     1         1
   df %>% mutate(df_col = data.frame(a2 = a)) %>% collect()
   #> Warning: Expression data.frame(a2 = a) not supported in Arrow; pulling 
data into
   #> R
   #> # A tibble: 1 × 2
   #>       a df_col$a2
   #>   <dbl>     <dbl>
   #> 1     1         1
   
   # duplicated cols
   df %>% mutate(df_col = tibble(a, a)) %>% collect()
   #> Warning: Expression tibble(a, a) not supported in Arrow; pulling data 
into R
   #> Error: Problem with `mutate()` column `df_col`.
   #> ℹ `df_col = tibble(a, a)`.
   #> x Column name `a` must not be duplicated.
   #> Use .name_repair to specify repair.
   df %>% mutate(df_col = data.frame(a, a)) %>% collect()
   #> Warning: Expression data.frame(a, a) not supported in Arrow; pulling data 
into R
   #> # A tibble: 1 × 2
   #>       a df_col$a  $a.1
   #>   <dbl>    <dbl> <dbl>
   #> 1     1        1     1
   df %>% mutate(df_col = data.frame(a, a, check.names = FALSE)) %>% collect()
   #> Warning: Expression data.frame(a, a, check.names = FALSE) not supported in
   #> Arrow; pulling data into R
   #> # A tibble: 1 × 2
   #>       a df_col$a    $a
   #>   <dbl>    <dbl> <dbl>
   #> 1     1        1     1
   
   # empty names
   df %>% 
     mutate(df_col = data.frame(a, check.names = TRUE, fix.empty.names = TRUE)) 
%>% 
     collect()
   #> Warning: Expression data.frame(a, check.names = TRUE, fix.empty.names = 
TRUE)
   #> not supported in Arrow; pulling data into R
   #> # A tibble: 1 × 2
   #>       a df_col$a
   #>   <dbl>    <dbl>
   #> 1     1        1
   df %>% 
     mutate(df_col = data.frame(a, check.names = TRUE, fix.empty.names = 
FALSE)) %>% 
     collect()
   #> Warning: Expression data.frame(a, check.names = TRUE, fix.empty.names = 
FALSE)
   #> not supported in Arrow; pulling data into R
   #> # A tibble: 1 × 2
   #>       a df_col$``
   #>   <dbl>     <dbl>
   #> 1     1         1
   df %>% 
     mutate(df_col = data.frame(a, check.names = FALSE, fix.empty.names = 
TRUE)) %>% 
     collect()
   #> Warning: Expression data.frame(a, check.names = FALSE, fix.empty.names = 
TRUE)
   #> not supported in Arrow; pulling data into R
   #> # A tibble: 1 × 2
   #>       a df_col$a
   #>   <dbl>    <dbl>
   #> 1     1        1
   df %>% 
     mutate(df_col = data.frame(a, check.names = FALSE, fix.empty.names = 
FALSE)) %>% 
     collect()
   #> Warning: Expression data.frame(a, check.names = FALSE, fix.empty.names = 
FALSE)
   #> not supported in Arrow; pulling data into R
   #> # A tibble: 1 × 2
   #>       a df_col$``
   #>   <dbl>     <dbl>
   #> 1     1         1
   
   # ignored
   df %>% mutate(df_col = data.frame(a, check.rows = TRUE)) %>% collect()
   #> Warning: Expression data.frame(a, check.rows = TRUE) not supported in 
Arrow;
   #> pulling data into R
   #> # A tibble: 1 × 2
   #>       a df_col$a
   #>   <dbl>    <dbl>
   #> 1     1        1
   df %>% mutate(df_col = data.frame(a, row.names = TRUE)) %>% collect()
   #> Warning: Expression data.frame(a, row.names = TRUE) not supported in 
Arrow;
   #> pulling data into R
   #> # A tibble: 1 × 2
   #>       a df_col$a
   #>   <dbl>    <dbl>
   #> 1     1        1
   ```
   
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to