[Scipy-svn] r6425 - in trunk/scipy/io/matlab: . tests
scipy-svn at scipy.org
scipy-svn at scipy.org
Sat May 29 17:48:01 EDT 2010
Author: matthew.brett at gmail.com
Date: 2010-05-29 16:48:01 -0500 (Sat, 29 May 2010)
New Revision: 6425
Modified:
trunk/scipy/io/matlab/mio.py
trunk/scipy/io/matlab/miobase.py
trunk/scipy/io/matlab/tests/test_mio.py
Log:
RF - deprecation warning about searching system path
Modified: trunk/scipy/io/matlab/mio.py
===================================================================
--- trunk/scipy/io/matlab/mio.py 2010-05-29 21:47:52 UTC (rev 6424)
+++ trunk/scipy/io/matlab/mio.py 2010-05-29 21:48:01 UTC (rev 6425)
@@ -30,8 +30,8 @@
possibly modified name after path search
'''
warnings.warn('Searching for mat files on python system path will be ' +
- 'removed in future versions of scipy',
- FutureWarning, stacklevel=2)
+ 'removed in next version of scipy',
+ DeprecationWarning, stacklevel=2)
if appendmat and file_name.endswith(".mat"):
file_name = file_name[:-4]
if os.sep in file_name:
@@ -54,6 +54,33 @@
pass
return full_name
+
+def _open_file(file_like, appendmat):
+ ''' Open `file_like` and return as file-like object '''
+ if isinstance(file_like, basestring):
+ try:
+ return open(file_like, 'rb')
+ except IOError:
+ pass
+ if appendmat and not file_like.endswith('.mat'):
+ try:
+ return open(file_like + '.mat', 'rb')
+ except IOError:
+ pass
+ # search the python path - we'll remove this soon
+ full_name = find_mat_file(file_like, appendmat)
+ if full_name is None:
+ raise IOError("%s not found on the path."
+ % file_like)
+ return open(full_name, 'rb')
+ # not a string - maybe file-like object
+ try:
+ file_like.read(0)
+ except AttributeError:
+ raise IOError('Reader needs file name or open file-like object')
+ return file_like
+
+
@docfiller
def mat_reader_factory(file_name, appendmat=True, **kwargs):
"""Create reader for matlab .mat format files
@@ -71,20 +98,7 @@
Initialized instance of MatFileReader class matching the mat file
type detected in `filename`.
"""
- if isinstance(file_name, basestring):
- try:
- byte_stream = open(file_name, 'rb')
- except IOError:
- full_name = find_mat_file(file_name, appendmat)
- if full_name is None:
- raise IOError, "%s not found on the path." % file_name
- byte_stream = open(full_name, 'rb')
- else:
- try:
- file_name.read(0)
- except AttributeError:
- raise IOError, 'Reader needs file name or open file-like object'
- byte_stream = file_name
+ byte_stream = _open_file(file_name, appendmat)
mjv, mnv = get_matfile_version(byte_stream)
if mjv == 0:
return MatFile4Reader(byte_stream, **kwargs)
Modified: trunk/scipy/io/matlab/miobase.py
===================================================================
--- trunk/scipy/io/matlab/miobase.py 2010-05-29 21:47:52 UTC (rev 6424)
+++ trunk/scipy/io/matlab/miobase.py 2010-05-29 21:48:01 UTC (rev 6425)
@@ -17,10 +17,7 @@
{'file_arg':
'''file_name : string
Name of the mat file (do not need .mat extension if
- appendmat==True) If name not a full path name, search for the
- file on the sys.path list and use the first one found (the
- current directory is searched first). Can also pass open
- file-like object''',
+ appendmat==True) Can also pass open file-like object''',
'append_arg':
'''appendmat : {True, False} optional
True to append the .mat extension to the end of the given
Modified: trunk/scipy/io/matlab/tests/test_mio.py
===================================================================
--- trunk/scipy/io/matlab/tests/test_mio.py 2010-05-29 21:47:52 UTC (rev 6424)
+++ trunk/scipy/io/matlab/tests/test_mio.py 2010-05-29 21:48:01 UTC (rev 6425)
@@ -362,7 +362,7 @@
# This should
yield assert_raises, FutureWarning, loadmat, fname
# This too
- yield assert_raises, FutureWarning, find_mat_file, fname
+ yield assert_raises, DeprecationWarning, find_mat_file, fname
warnings.resetwarnings()
More information about the Scipy-svn
mailing list