Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a6b449c

Browse files
gpoulterNeil
authored andcommitted
Deterministically initialising recarray because uninitialised memory sometimes produces floats that do not round trip to string and back.
1 parent 67427c3 commit a6b449c

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

lib/matplotlib/tests/test_mlab.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ def test_colinear_pca():
1414
def test_recarray_csv_roundtrip():
1515
expected = np.recarray((99,),
1616
[('x',np.float),('y',np.float),('t',np.float)])
17-
expected['x'][0] = 1
18-
expected['y'][1] = 2
19-
expected['t'][2] = 3
17+
# initialising all values: uninitialised memory sometimes produces floats
18+
# that do not round-trip to string and back.
19+
expected['x'] = np.linspace(0,1e-200,99)
20+
expected['y'] = np.linspace(0,1,99)
21+
expected['t'] = np.linspace(0,1e300,99)
2022
fd = tempfile.TemporaryFile(suffix='csv', mode="w+")
2123
mlab.rec2csv(expected,fd)
2224
fd.seek(0)

0 commit comments

Comments
 (0)