[ 
https://issues.apache.org/jira/browse/ARROW-14028?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17417055#comment-17417055
 ] 

Joris Van den Bossche commented on ARROW-14028:
-----------------------------------------------

In Arrow world, NaN and NA/null are not the same, so I am not sure this should 
cast this way? (at least not without a specific option)

Numpy doesn't know a concept of NA_integer, it only has the full range of 
integers. So when casting float with NaNs to integer, you get also get the 
sentinel value as above (but in contrast to Arrow, numpy does that by default, 
while in Arrow only if you enable unsafe casts)

 

> [R] Cast of NaN to integer should return NA_integer_
> ----------------------------------------------------
>
>                 Key: ARROW-14028
>                 URL: https://issues.apache.org/jira/browse/ARROW-14028
>             Project: Apache Arrow
>          Issue Type: Improvement
>          Components: R
>            Reporter: Ian Cook
>            Priority: Major
>
> Casting double {{NaN}} to integer returns a sentinel value:
> {code:r}
> call_function("cast", Scalar$create(NaN), options = list(to_type = int32(), 
> allow_float_truncate = TRUE))
> #> Scalar
> #> -2147483648
> call_function("cast", Scalar$create(NaN), options = list(to_type = int64(), 
> allow_float_truncate = TRUE))
> #> Scalar
> #> -9223372036854775808{code}
> It would be nice if this would instead return {{NA_integer}}.
> N.B. for some reason this doesn't reproduce in dplyr unless you round-trip it 
> back to double:
> {code:r}
> > Table$create(x = NaN) %>% transmute(as.double(as.integer(x))) %>% pull(1)
> #> [1] -2147483648{code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to