Closed
Description
In Python 3, round(_float_)
returns an integer, but round(_np.float64_)
returns a float:
>>> np.float64(1).__round__()
1.0
>>> 1.0.__round__()
1
The result is that if a np.float64
seeps into my data, the stock round
produces unexpected results: round(x)
can be an integer or a float depending on whether x
is a regular float
or a np.float64
.
>>> [type(round(t(1))).__name__ for t in [float, np.float16, np.float32, np.float64, np.float128]]
['int', 'float16', 'float32', 'float64', 'float128']
The distinction does matter, e.g., np.partition
raises TypeError: Partition index must be integer
.
PS. Python 3.7.0, numpy 1.14.5