[
https://issues.apache.org/jira/browse/ARROW-12387?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17322011#comment-17322011
]
Joris Van den Bossche commented on ARROW-12387:
-----------------------------------------------
[~ktaras] for arrays, the default is to use a safe cast, but you can override
that by passing {{safe=False}}:
{code:python}
>>> b = pa.array(arr, pa.float64())
>>> pc.multiply(b, 1e8).cast(pa.int64(), safe=False)
<pyarrow.lib.Int64Array object at 0x7f167414ba00>
[
99213380,
99310344
]
{code}
Now, that the scalar version does an unsafe cast by default is a bit
inconsistent. That's something we should probably fix.
> [C++][Python] cannot cast float64 array to int64
> ------------------------------------------------
>
> Key: ARROW-12387
> URL: https://issues.apache.org/jira/browse/ARROW-12387
> Project: Apache Arrow
> Issue Type: Bug
> Components: C++, Python
> Affects Versions: 3.0.0
> Reporter: Taras Kuzyo
> Priority: Major
>
>
> {code:java}
> >>> arr = [0.992133801741256, 0.993103448275862]
> >>> a = pa.scalar(arr[0], pa.float64())
> >>> pc.multiply(a, 1e8).cast(pa.int64())
> <pyarrow.Int64Scalar: 99213380>
> >>> b = pa.array(arr, pa.float64())
> >>> pc.multiply(b, 1e8).cast(pa.int64())
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "pyarrow/array.pxi", line 810, in pyarrow.lib.Array.cast
> File "/usr/local/lib/python3.6/dist-packages/pyarrow/compute.py", line 281,
> in cast
> return call_function("cast", [arr], options)
> File "pyarrow/_compute.pyx", line 465, in pyarrow._compute.call_function
> File "pyarrow/_compute.pyx", line 294, in pyarrow._compute.Function.call
> File "pyarrow/error.pxi", line 122, in
> pyarrow.lib.pyarrow_internal_check_status
> File "pyarrow/error.pxi", line 84, in pyarrow.lib.check_status
> pyarrow.lib.ArrowInvalid: Float value 9.92134e+07 was truncated converting
> toint64
> {code}
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)