pitrou commented on issue #48409:
URL: https://github.com/apache/arrow/issues/48409#issuecomment-3654615515
There's one complication that we should be careful about: if we change the
meaning the `__eq__`, then the use of equality in boolean context will result
in calling the `__bool__` of the result array (which is always true unless the
array is empty). `if x == y` would then always succeed if the arrays are not
empty, which I hope we agree is extremely error-prone:
```python
>>> bool(np.array([False, False, False]))
Traceback (most recent call last):
Cell In[15], line 1
bool(np.array([False, False, False]))
ValueError: The truth value of an array with more than one element is
ambiguous. Use a.any() or a.all()
>>> bool(pa.array([False, False, False]))
True
```
So, if we change the meaning the `__eq__` on arrays, we must also deprecate
`__bool__` like NumPy did. The cost and annoyance of that change may outweigh
the benefits of different `__eq__` semantics.
Perhaps it would be less disruptive if `__eq__` continues doing the Pythonic
thing of returning a bool, and `equals` is changed to call the compute
function. But that would make us different from NumPy (is that a problem?).
--
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]