[Numpy-discussion] Re: Comparison between numpy scalars returns numpy bool class and not native python bool class

2024-06-27 Thread Aaron Meurer
On Thu, Jun 27, 2024 at 3:48 PM Aaron Meurer wrote: > > Apparently the reason this happens is that True, False, and None are > compared using 'is' in structural pattern matching (see > https://peps.python.org/pep-0634/#literal-patterns). > > There's no way NumPy could avoid this. First off, Python

[Numpy-discussion] Re: Comparison between numpy scalars returns numpy bool class and not native python bool class

2024-06-27 Thread Aaron Meurer
Apparently the reason this happens is that True, False, and None are compared using 'is' in structural pattern matching (see https://peps.python.org/pep-0634/#literal-patterns). There's no way NumPy could avoid this. First off, Python won't even let you subclass bool: >>> class mybool(bool): ...

[Numpy-discussion] Comparison between numpy scalars returns numpy bool class and not native python bool class

2024-06-27 Thread Stefano Miccoli via NumPy-Discussion
It is well known that ‘np.bool' is not interchangeable with python ‘bool’, and in fact 'issubclass(np.bool, bool)’ is false. On the contrary, numpy floats are subclassing python floats—'issubclass(np.float64, float) is true—so I’m wondering if the fact that scalar comparison returns a np.bool b