The following code produces different results in python 2.7.5.final.0 with pandas 0.15.1 and numpy 1.9.1 and in python 2.7.11.final.0 with pandas 0.18.0 and numpy 1.10.4 (the anaconda package).
The former version gives the result 18292498239.8
; the latter, 18292498239.824
.
import numpy as np
import pandas as pd
x = 18292498239.824
df = pd.DataFrame({'One': x},index=["bignum"])
df.to_csv('junktest.txt')
fh = open('junktest.txt','rb')
res = fh.read().split('\n')[1].split(',')[1]
print "Result:",res
But if we set x to 292498239.824
, we get the same result from both: 292498239.824
. If we go up an order of magnitude (x = 118292498239.824
), the results are 1.1829249824e+11
and 118292498239.824
.
It looks like the later version of pandas.DataFrame.to_csv()
restricts floats to 12 digits, but I cannot find anything in the pandas documentation to tell when the change occurred -- or why.
This caused some of my unit tests to fail upon upgrading to anaconda; I would like to be able to upgrade without having to substantially revise my tests.