summaryrefslogtreecommitdiff
path: root/numpy/lib/format.py
diff options
context:
space:
mode:
authorBlake Griffith <blake.a.griffith@gmail.com>2015-03-24 15:36:30 -0500
committerBlake Griffith <blake.a.griffith@gmail.com>2015-04-05 18:56:55 -0500
commit475a6403f9b10d2c4fa30fa0ad807b9ca1d2d0d6 (patch)
treebf9fbd969214940f15d50915853962e4076c7702 /numpy/lib/format.py
parent4e0cd7b9585ad6da1fce9fe35596b88e8204af0d (diff)
downloadnumpy-475a6403f9b10d2c4fa30fa0ad807b9ca1d2d0d6.tar.gz
BUG: don't ignore version passed to format.write_array
Previously the passed in version was ignored
Diffstat (limited to 'numpy/lib/format.py')
-rw-r--r--numpy/lib/format.py20
1 files changed, 9 insertions, 11 deletions
diff --git a/numpy/lib/format.py b/numpy/lib/format.py
index 4f96ff4bc..a0405b310 100644
--- a/numpy/lib/format.py
+++ b/numpy/lib/format.py
@@ -314,21 +314,19 @@ def _write_array_header(fp, d, version=None):
header = header + ' '*topad + '\n'
header = asbytes(_filter_header(header))
- if len(header) >= (256*256) and version == (1, 0):
- raise ValueError("header does not fit inside %s bytes required by the"
- " 1.0 format" % (256*256))
- if len(header) < (256*256):
- header_len_str = struct.pack('<H', len(header))
+ hlen = len(header)
+ if hlen < 256*256 and version in (None, (1, 0)):
version = (1, 0)
- elif len(header) < (2**32):
- header_len_str = struct.pack('<I', len(header))
+ header_prefix = magic(1, 0) + struct.pack('<H', hlen)
+ elif hlen < 2**32 and version in (None, (2, 0)):
version = (2, 0)
+ header_prefix = magic(2, 0) + struct.pack('<I', hlen)
else:
- raise ValueError("header does not fit inside 4 GiB required by "
- "the 2.0 format")
+ msg = "Header length %s too big for version=%s"
+ msg %= (hlen, version)
+ raise ValueError(msg)
- fp.write(magic(*version))
- fp.write(header_len_str)
+ fp.write(header_prefix)
fp.write(header)
return version