diff options
author | Max Sperlich <max.sperlich@livingsocial.com> | 2013-12-09 19:44:36 -0500 |
---|---|---|
committer | Max Sperlich <max.sperlich@livingsocial.com> | 2013-12-09 20:07:51 -0500 |
commit | bdb6f8cabf755d4d7b18a3d7e7475480ce6fc008 (patch) | |
tree | 837f32711e73a856adc2b89feccf967bb97a411a /numpy/lib/format.py | |
parent | 161ca8ff732ed58613b9bdcb2f1dcad7178a76c5 (diff) | |
download | numpy-bdb6f8cabf755d4d7b18a3d7e7475480ce6fc008.tar.gz |
MAINT: Better handling of very small chunks
Issue 4093: Improved the handling of the case when the amount of data
read by fp.read is smaller than dtype.itemsize. Also changed the test
code to make sure this case is tested.
Diffstat (limited to 'numpy/lib/format.py')
-rw-r--r-- | numpy/lib/format.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/numpy/lib/format.py b/numpy/lib/format.py index 2dd1a68af..81366c50d 100644 --- a/numpy/lib/format.py +++ b/numpy/lib/format.py @@ -486,10 +486,11 @@ def read_array(fp): msg = "EOF: expected %d entries, got %d entries" % (count, i) raise ValueError(msg) actual_count = len(data) // dtype.itemsize - extra_data = data[actual_count*dtype.itemsize:] - array[i:i+actual_count] = numpy.frombuffer(data, dtype=dtype, - count=actual_count) - i += actual_count + if actual_count > 0: + array[i:i + actual_count] = \ + numpy.frombuffer(data, dtype=dtype, count=actual_count) + i += actual_count + extra_data = data[actual_count * dtype.itemsize:] if fortran_order: array.shape = shape[::-1] |