You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "jorisvandenbossche (via GitHub)" <gi...@apache.org> on 2023/04/11 13:54:17 UTC

[GitHub] [arrow] jorisvandenbossche commented on issue #34901: [Python] Inconsistent cast behavior between array and scalar for int64

jorisvandenbossche commented on issue #34901:
URL: https://github.com/apache/arrow/issues/34901#issuecomment-1503400417

   > Numpy defaults to unsafe casting (https://numpy.org/doc/stable/reference/generated/numpy.ndarray.astype.html), but it seems it also doesn't perform safety checks properly all of the time.
   
   Sidenote: numpy doesn't really have the same concept of "safe" casting as how we use this in pyarrow. In pyarrow this depends on the _values_, while in numpy this is just a property of a cast between two _dtypes_. So to say if a cast from one dtype to another is safe or not, numpy needs to make some generalization/assumption, and so it seems it decided that casting int to float is generally safe (indeed, except for large ints) and casting floats to ints is generally not safe (indeed, except if you have rounded floats):
   
   ```python
   >>> np.can_cast(np.int64(), np.float64(), casting="safe")
   True
   >>> np.can_cast(np.float64(), np.int64(), casting="safe")
   False
   ```


-- 
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: github-unsubscribe@arrow.apache.org

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