You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/05/18 08:09:37 UTC

[GitHub] [arrow] lf-shaw opened a new issue #10351: [python] Int64Array can not be casted to DoubleArray?

lf-shaw opened a new issue #10351:
URL: https://github.com/apache/arrow/issues/10351


   In numpy, we can cast int64 to float64. But in pyarrow, we can't.  
   
   ```python
   import pandas as pd
   import pyarrow as pa
   
   # timestamp
   dt = pd.date_range('2021-01-01', periods=10)
   
   # int64
   arr = dt.asi8
   
   # cast to float64
   arr_double = arr.astype(np.float64)
   
   # to arrow array
   ts = pa.array(dt.asi8, type=pa.timestamp('ns'))
   
   # to int64 array
   ts_int64 = ts.cast(pa.int64())
   
   # cast to float64
   ts_double = ts_int64.cast(pa.float64())
   ```
   
   the last line raise an exception
   
   ```python
   ---------------------------------------------------------------------------
   ArrowInvalid                              Traceback (most recent call last)
   <ipython-input-89-cc7cafd418c4> in <module>
   ----> 1 pa.array(dt.asi8, type=pa.timestamp('ns')).cast(pa.int64()).cast(pa.float64())
   
   /opt/anaconda3/lib/python3.8/site-packages/pyarrow/array.pxi in pyarrow.lib.Array.cast()
   
   /opt/anaconda3/lib/python3.8/site-packages/pyarrow/compute.py in cast(arr, target_type, safe)
       287     else:
       288         options = CastOptions.unsafe(target_type)
   --> 289     return call_function("cast", [arr], options)
       290 
       291 
   
   /opt/anaconda3/lib/python3.8/site-packages/pyarrow/_compute.pyx in pyarrow._compute.call_function()
   
   /opt/anaconda3/lib/python3.8/site-packages/pyarrow/_compute.pyx in pyarrow._compute.Function.call()
   
   /opt/anaconda3/lib/python3.8/site-packages/pyarrow/error.pxi in pyarrow.lib.pyarrow_internal_check_status()
   
   /opt/anaconda3/lib/python3.8/site-packages/pyarrow/error.pxi in pyarrow.lib.check_status()
   
   ArrowInvalid: Integer value 1609459200000000000 not in range: -9007199254740992 to 9007199254740992
   ```


-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] lidavidm closed issue #10351: [python] Int64Array can not be casted to DoubleArray?

Posted by GitBox <gi...@apache.org>.
lidavidm closed issue #10351:
URL: https://github.com/apache/arrow/issues/10351


   


-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] lidavidm commented on issue #10351: [python] Int64Array can not be casted to DoubleArray?

Posted by GitBox <gi...@apache.org>.
lidavidm commented on issue #10351:
URL: https://github.com/apache/arrow/issues/10351#issuecomment-843260793


   Hey @lf-shaw, I see you also made a JIRA at ARROW-12818 (thanks!) - let's continue the discussion there.


-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org