[Numpy-discussion] New DTypes: Are scalars a central concept in NumPy or not?
Stefano Miccoli
stefano.miccoli at polimi.it
Tue Feb 25 04:00:59 EST 2020
The fact that `isinstance(np.float64(1), float)` raises the problem that the current
implementation of np.float64 scalars breaks the Liskov substitution principle:
`sequence_or_array[round(x)]` works if `x` is a float, but breaks down if x is
a np.float64.
See https://github.com/numpy/numpy/issues/11810, where the issue is discussed in the
broader setting of the semantics of `np.round` vs. python3 `round`.
I do not have a strong opinion here, except that if np.float64’s are within the python
number hierarchy they should be PEP 3141 compliant (which currently they are not.)
Stefano
> On 25 Feb 2020, at 00:03, numpy-discussion-request at python.org wrote:
>
> Also, something to think about is that currently numpy scalars satisfy
> the property `isinstance(np.float64(1), float)`, i.e they are within the
> python numerical type hierarchy. 0d arrays do not have this property. My
> proposal above would break this. I'm not sure what to think about
> whether this is a good property to maintain or not.
>
> Cheers,
> Allan
More information about the NumPy-Discussion
mailing list