diff options
author | dhuard <dhuard@localhost> | 2008-04-04 20:13:24 +0000 |
---|---|---|
committer | dhuard <dhuard@localhost> | 2008-04-04 20:13:24 +0000 |
commit | f2e6d8e233d380133d8e3504272b3ed0554bfaa4 (patch) | |
tree | a072490fe4fd2d36d27ade3fbe41ebaa40cd9fa2 /numpy/lib | |
parent | 343841340122a5c5bd2071584e81ad8e027e6389 (diff) | |
download | numpy-f2e6d8e233d380133d8e3504272b3ed0554bfaa4.tar.gz |
Modified io._getconv to allow loading values stored as float as integers arrays. Added test to check the behavior as suggested in the comment from b. southey in
ticket #623
Diffstat (limited to 'numpy/lib')
-rw-r--r-- | numpy/lib/io.py | 2 | ||||
-rw-r--r-- | numpy/lib/tests/test_io.py | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/numpy/lib/io.py b/numpy/lib/io.py index bb4d254a8..235316c82 100644 --- a/numpy/lib/io.py +++ b/numpy/lib/io.py @@ -203,7 +203,7 @@ def _getconv(dtype): if issubclass(typ, np.bool_): return lambda x: bool(int(x)) if issubclass(typ, np.integer): - return int + return lambda x: int(float(x)) elif issubclass(typ, np.floating): return float elif issubclass(typ, np.complex): diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index 35203a38d..c219f6fcd 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -41,6 +41,16 @@ class Testloadtxt(NumpyTestCase): a = np.array([(1, 2), (3, 4)], dtype=[('x', '<i4'), ('y', '<i4')]) assert_array_equal(x, a) + d = StringIO.StringIO() + d.write('M 64.0 75.0\nF 25.0 60.0') + d.seek(0) + + mydescriptor = {'names': ('gender','age','weight'), 'formats': ('S1', + 'i4', 'f4')} + b = np.array([('M', 64.0, 75.0),('F', 25.0, 60.0)], dtype=mydescriptor) + y = np.loadtxt(d, dtype=mydescriptor) + assert_array_equal(y, b) + def test_array(self): c = StringIO.StringIO() c.write('1 2\n3 4') |