summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/core/records.py16
-rw-r--r--numpy/lib/index_tricks.py2
2 files changed, 12 insertions, 6 deletions
diff --git a/numpy/core/records.py b/numpy/core/records.py
index aebf3b3c2..50f5114b2 100644
--- a/numpy/core/records.py
+++ b/numpy/core/records.py
@@ -4,7 +4,7 @@ import numeric as sb
from defchararray import chararray
import numerictypes as nt
import types
-import stat, os
+import os
_byteorderconv = {'b':'>',
'l':'<',
@@ -360,6 +360,15 @@ def fromstring(datastring, formats, shape=None, names=None, titles=None,
byteorder=byteorder)
return _array
+def get_remaining_size(fd):
+ try:
+ fn = fd.fileno()
+ except AttributeError:
+ return os.path.getsize(fd.name) - fd.tell()
+ st = os.fstat(fn)
+ size = st.st_size - fd.tell()
+ return size
+
def fromfile(fd, formats, shape=None, names=None, titles=None,
byteorder=None, aligned=0, offset=0):
"""Create an array from binary file data
@@ -388,10 +397,7 @@ def fromfile(fd, formats, shape=None, names=None, titles=None,
fd = open(fd, 'rb')
if (offset > 0):
fd.seek(offset, 1)
- try:
- size = os.fstat(fd.fileno())[stat.ST_SIZE] - fd.tell()
- except:
- size = os.path.getsize(fd.name) - fd.tell()
+ size = get_remaining_size(fd)
parsed = format_parser(formats, names, titles, aligned)
itemsize = parsed._descr.itemsize
diff --git a/numpy/lib/index_tricks.py b/numpy/lib/index_tricks.py
index 6f06bab78..a0900c845 100644
--- a/numpy/lib/index_tricks.py
+++ b/numpy/lib/index_tricks.py
@@ -238,7 +238,7 @@ class concatenator(object):
try:
self.axis = int(key[k])
continue
- except:
+ except (ValueError, TypeError):
raise ValueError, "unknown special directive"
elif type(key[k]) in ScalarType:
newobj = asarray([key[k]])