roblanf / SRHtests

tests of stationarity, reversibility, and homogeneity for sequence alignments
2 stars 3 forks source link

numpy bug???? #4

Open roblanf opened 6 years ago

roblanf commented 6 years ago

Is numpy cutting digits off when it converts to string??

Reproducible example:

Where it does a bad thing...

p=np.empty([2,6],dtype='U21')
p[0] = np.array(['Dataset','Charset','Test','Sp1','Sp2','pvalue'])
a = 4.4226657709978134e-05
p[1] = np.array(['Dataset','Charset','Test','Sp1','Sp2', a])
p

but changing one digit of the input number seems to work fine:

p=np.empty([2,6],dtype='U21')
p[0] = np.array(['Dataset','Charset','Test','Sp1','Sp2','pvalue'])
a = 4.4226657709978139e-05
p[1] = np.array(['Dataset','Charset','Test','Sp1','Sp2', a])
p
roblanf commented 6 years ago

It happens with the last digit as:

2, 3, 4, 5

but not with

1, 9, 8, 0

roblanf commented 6 years ago

using a pandas dataframe should be good.

This almost works (but I'm not good enough at pandas...)

p=pd.DataFrame()
columns = ['Dataset','Charset','Test','Sp1','Sp2','pvalue']
pd.DataFrame(columns=columns)
a = 4.4226657709978134e-05
p.append(pd.DataFrame([['Dataset','Charset','Test','Sp1','Sp2', a]], columns=columns), ignore_index=True)
p

almost works, but not quite...

roblanf commented 6 years ago

Additional note. The numpy behaviour above was with Python 3.5.4

and numpy 1.11.1-py35_0

Updating numpy to 1.14.2-py35ha9ae307_1

the same issue occurs