diff options
author | Justin Peel <jpscipy@gmail.com> | 2011-01-23 16:56:15 -0700 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2011-01-23 16:59:56 -0700 |
commit | 437e555e0b2a742f0d5af88132f68fbe96dcbc3f (patch) | |
tree | c271a293e16a808b2fe4d2eac7fb24dd0b1e48ce | |
parent | 265ac4f50ca4ef224daed906d9e0c6244e04e030 (diff) | |
download | numpy-437e555e0b2a742f0d5af88132f68fbe96dcbc3f.tar.gz |
BUG: Ticket #1703, make fromfile work with dtype=np.bool_ and floats.
-rw-r--r-- | numpy/core/src/multiarray/arraytypes.c.src | 10 | ||||
-rw-r--r-- | numpy/core/tests/test_multiarray.py | 11 |
2 files changed, 16 insertions, 5 deletions
diff --git a/numpy/core/src/multiarray/arraytypes.c.src b/numpy/core/src/multiarray/arraytypes.c.src index c9d517c50..de84911c1 100644 --- a/numpy/core/src/multiarray/arraytypes.c.src +++ b/numpy/core/src/multiarray/arraytypes.c.src @@ -1735,12 +1735,12 @@ static int static int BOOL_scan(FILE *fp, Bool *ip, void *NPY_UNUSED(ignore), PyArray_Descr *NPY_UNUSED(ignore2)) { - int temp; - int num; + double result; + int ret; - num = fscanf(fp, "%d", &temp); - *ip = (Bool) (temp != 0); - return num; + ret = NumPyOS_ascii_ftolf(fp, &result); + *ip = (Bool) (result != 0.0); + return ret; } /**begin repeat diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index e1d302126..03779f83c 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -1150,6 +1150,17 @@ class TestIO(object): v = np.array([1,2,3,4], dtype=np.int_) self._check_from('1,2,3,4', v, sep=',', dtype=np.int_) + def test_dtype_bool(self): + # can't use _check_from because fromstring can't handle True/False + v = np.array([True, False, True, False], dtype=np.bool_) + s = '1,0,-2.3,0' + f = open(self.filename, 'wb') + f.write(asbytes(s)) + f.close() + y = np.fromfile(self.filename, sep=',', dtype=np.bool_) + assert_(y.dtype == '?') + assert_array_equal(y, v) + def test_tofile_sep(self): x = np.array([1.51, 2, 3.51, 4], dtype=float) f = open(self.filename, 'w') |