Reputation: 9015
When I have updated the numpy
version from 1.11.3
to 1.16.5
, my tests are failing because of of fraction difference between the values calculated by the percentile
method.
numpy = 1.11.3
import numpy as np
print (np.percentile([1.0, 0.0, 0.0, 0.0], [15.0, 85.0])[1])
> 0.54999999999999982
numpy = 1.16.5
import numpy as np
print (np.percentile([1.0, 0.0, 0.0, 0.0], [15.0, 85.0])[1])
> 0.5499999999999998
I am looking for an answer that what has changed that is causing the failure, I wanted to understand the upgrade so that I do not get unexpected results once released to prod.
Thanks.
Upvotes: 3
Views: 180
Reputation: 1099
Actually your test is fine, you are just printing two different precisions
import numpy as np
print (np.percentile([1.0, 0.0, 0.0, 0.0], [15.0, 85.0])[1])
> 0.54999999999999982 # has 17 decimal places
import numpy as np
print (np.percentile([1.0, 0.0, 0.0, 0.0], [15.0, 85.0])[1])
> 0.5499999999999998 # has only 16
the actual value is indeed 0.54999999999999982236
. So your test is fine.
To make sure your numeric tests with numpy
work as expected , you can setup the precision of printed values with np.set_printoptions(precision=20)
.
Upvotes: 1