Chetansahney opened a new issue, #55636:
URL: https://github.com/apache/arrow/issues/55636

   ### Describe the bug, including details regarding any error messages, 
version, and platform.
   
   `Logb` in `cpp/src/arrow/compute/kernels/scalar_arithmetic.cc` special-cases 
`x == 0.0` and returns `-inf` for every base that is not zero or negative:
   
   ```cpp
   if (x == 0.0) {
     if (base == 0.0 || base < 0.0) {
       return std::numeric_limits<T>::quiet_NaN();
     } else {
       return -std::numeric_limits<T>::infinity();
     }
   }
   ```
   
   That is only right for `base > 1`. For `0 < base < 1`, `log(base)` is 
negative, so `log_base(0)` is `+inf`. A NaN base should give NaN, and an 
infinite base gives `-inf / inf`, which is NaN.
   
   ```python
   import numpy as np
   import pyarrow as pa
   import pyarrow.compute as pc
   
   base = pa.array([0.5, 0.1, np.inf, np.nan, 2.0])
   x = pa.array([0.0] * len(base))
   with np.errstate(divide="ignore", invalid="ignore"):
       expected = np.log(x.to_numpy()) / np.log(base.to_numpy())
   print("logb    ", pc.logb(x, base).to_pylist())
   print("expected", expected.tolist())
   ```
   
   Output with pyarrow 26.0.1 (Windows, Python 3.12):
   
   ```
   logb     [-inf, -inf, -inf, -inf, -inf]
   expected [inf, inf, nan, nan, -inf]
   ```
   
   Without the special case, `std::log(x) / std::log(base)` already gives the 
right values here, since `std::log(0.0)` is `-inf`. The `x < 0.0` branch is 
also covered by `std::log` returning NaN. So one fix is to drop the `x == 0.0` 
branch, or make it return `-inf / std::log(base)`. `logb_checked` raises for `x 
== 0` and is not affected.
   
   ### Component(s)
   
   C++, Python
   


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