You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@arrow.apache.org by "Krisztian Szucs (JIRA)" <ji...@apache.org> on 2018/09/18 10:24:00 UTC
[jira] [Comment Edited] (ARROW-2854) [C++/Python] Casting float NaN
to int should raise an error on safe cast
[ https://issues.apache.org/jira/browse/ARROW-2854?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16618865#comment-16618865 ]
Krisztian Szucs edited comment on ARROW-2854 at 9/18/18 10:23 AM:
------------------------------------------------------------------
`ARROW-3158: [C++] Handle float truncation during casting` has resolved this case:
{code:python}
>>> pa.array([np.nan, 1.]).cast(pa.int64())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pyarrow/array.pxi", line 413, in pyarrow.lib.Array.cast
check_status(Cast(_context(), self.ap[0], type.sp_type,
File "pyarrow/error.pxi", line 81, in pyarrow.lib.check_status
raise ArrowInvalid(message)
pyarrow.lib.ArrowInvalid: Floating point value truncated
{code}
{code:python}
>>> pa.array([np.nan, 1.]).cast(pa.int64(), safe=False)
<pyarrow.lib.Int64Array object at 0x116155778>
[
-9223372036854775808,
1
]
{code}
Of course the error message could be better.
was (Author: kszucs):
`ARROW-3158: [C++] Handle float truncation during casting` has resolved this case:
{code:python}
>>> pa.array([np.nan, 1.]).cast(pa.int64())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pyarrow/array.pxi", line 413, in pyarrow.lib.Array.cast
check_status(Cast(_context(), self.ap[0], type.sp_type,
File "pyarrow/error.pxi", line 81, in pyarrow.lib.check_status
raise ArrowInvalid(message)
pyarrow.lib.ArrowInvalid: Floating point value truncated
{code}
{code:python}
>>> pa.array([np.nan, 1.]).cast(pa.int64(), safe=False)
<pyarrow.lib.Int64Array object at 0x116155778>
[
-9223372036854775808,
1
]
{code}
> [C++/Python] Casting float NaN to int should raise an error on safe cast
> ------------------------------------------------------------------------
>
> Key: ARROW-2854
> URL: https://issues.apache.org/jira/browse/ARROW-2854
> Project: Apache Arrow
> Issue Type: Bug
> Components: C++, Python
> Affects Versions: 0.9.0
> Reporter: Uwe L. Korn
> Priority: Major
> Fix For: 0.11.0
>
>
> Currently the following code works:
> {code}
> pa.array([np.nan, 1.]).cast(pa.int64())
> {code}
> It produces:
> {code}
> <pyarrow.lib.Int64Array object at 0x111ca6778>
> [
> -9223372036854775808,
> 1
> ]
> {code}
> The expected behaviour should be that it raises.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)