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

   @jbrockmendel Using the `divide` kernel with integers does "integer 
division" (which is the standard behaviour in C++), so like `//` in python:
   
   ```
   In [26]: pc.divide([1, 2, 3, 4, 5], 3).to_pylist()
   Out[26]: [0, 0, 1, 1, 1]
   
   In [27]: np.array([1, 2, 3, 4, 5]) // 3
   Out[27]: array([0, 0, 1, 1, 1])
   ```
   
   Numpy and pandas actually always return floats for standard division with 
integers. If you want this with Arrow, I think the only workaround right now is 
to explicitly cast one of both operands to float to trigger standard floating 
point division (we should maybe consider enabling float output without having 
to do this cast). 
   
   For integer division, you can't "behave as float", since there is no Inf or 
NaN for integers. It seems that numpy then uses 0 though:
   
   ```
   In [29]: np.array([0, 1, 2]) // 0
   <ipython-input-29-cf533e0a640a>:1: RuntimeWarning: divide by zero 
encountered in floor_divide
     np.array([0, 1, 2]) // 0
   Out[29]: array([0, 0, 0])
   ```
   
   But I don't know if we want to remove the divide-by-zero error from the 
non-checked variant and return 0 instead.
   
   Similar previous issue: https://github.com/apache/arrow/issues/29427


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to