Skip to content
Browse files

STY: Update exception styles, trickier ones.

  • Loading branch information...
1 parent cfd7664 commit e1a9692cc36e4353798a332c834fce7aa6cf9b54 @charris charris committed
View
8 numpy/core/_mx_datetime_parser.py
@@ -282,10 +282,10 @@ def utc_offset(zone):
return _zonetable[uzone]*60
offset = _zoneoffsetRE.match(zone)
if not offset:
- raise ValueError,'wrong format or unkown time zone: "%s"' % zone
+ raise ValueError('wrong format or unkown time zone: "%s"' % zone)
zonesign,hours,minutes,extra = offset.groups()
if extra:
- raise ValueError,'illegal time zone offset: "%s"' % zone
+ raise ValueError('illegal time zone offset: "%s"' % zone)
offset = int(hours or 0) * 60 + int(minutes or 0)
if zonesign == '-':
offset = -offset
@@ -518,7 +518,7 @@ def _parse_date(text):
elif not style:
# Not recognized: raise an error
- raise ValueError, 'unknown date format: "%s"' % text
+ raise ValueError('unknown date format: "%s"' % text)
# Literal date post-processing
if style in ('lit', 'altlit', 'eurlit'):
@@ -610,7 +610,7 @@ def _parse_time(text):
if not style:
# If no default handling should be applied, raise an error
- raise ValueError, 'unknown time format: "%s"' % text
+ raise ValueError('unknown time format: "%s"' % text)
# Post-processing
if match is not None:
View
2 numpy/core/getlimits.py
@@ -104,7 +104,7 @@ def __new__(cls, dtype):
dtypes.append(newdtype)
dtype = newdtype
if not issubclass(dtype, numeric.inexact):
- raise ValueError, "data type %r not inexact" % (dtype)
+ raise ValueError("data type %r not inexact" % (dtype))
obj = cls._finfo_cache.get(dtype,None)
if obj is not None:
return obj
View
6 numpy/core/numeric.py
@@ -2179,11 +2179,11 @@ def setbufsize(size):
"""
if size > 10e6:
- raise ValueError, "Buffer size, %s, is too big." % size
+ raise ValueError("Buffer size, %s, is too big." % size)
if size < 5:
- raise ValueError, "Buffer size, %s, is too small." %size
+ raise ValueError("Buffer size, %s, is too small." %size)
if size % 16 != 0:
- raise ValueError, "Buffer size, %s, is not a multiple of 16." %size
+ raise ValueError("Buffer size, %s, is not a multiple of 16." %size)
pyvals = umath.geterrobj()
old = getbufsize()
View
12 numpy/core/records.py
@@ -174,7 +174,7 @@ def _setfieldnames(self, names, titles):
elif (type(names) == str):
names = names.split(',')
else:
- raise NameError, "illegal input names %s" % `names`
+ raise NameError("illegal input names %s" % `names`)
self._names = [n.strip() for n in names[:self._nfields]]
else:
@@ -189,7 +189,7 @@ def _setfieldnames(self, names, titles):
# check for redundant names
_dup = find_duplicate(self._names)
if _dup:
- raise ValueError, "Duplicate field names: %s" % _dup
+ raise ValueError("Duplicate field names: %s" % _dup)
if (titles):
self._titles = [n.strip() for n in titles[:self._nfields]]
@@ -250,7 +250,7 @@ def __getattribute__(self, attr):
def __setattr__(self, attr, val):
if attr in ['setfield', 'getfield', 'dtype']:
- raise AttributeError, "Cannot set '%s' attribute" % attr
+ raise AttributeError("Cannot set '%s' attribute" % attr)
fielddict = nt.void.__getattribute__(self, 'dtype').fields
res = fielddict.get(attr, None)
if res:
@@ -413,7 +413,7 @@ def __getattribute__(self, attr):
try:
res = fielddict[attr][:2]
except (TypeError, KeyError):
- raise AttributeError, "record array has no attribute %s" % attr
+ raise AttributeError("record array has no attribute %s" % attr)
obj = self.getfield(*res)
# if it has fields return a recarray, otherwise return
# normal array
@@ -450,7 +450,7 @@ def __setattr__(self, attr, val):
try:
res = fielddict[attr][:2]
except (TypeError, KeyError):
- raise AttributeError, "record array has no attribute %s" % attr
+ raise AttributeError("record array has no attribute %s" % attr)
return self.setfield(val, *res)
def __getitem__(self, indx):
@@ -557,7 +557,7 @@ def fromarrays(arrayList, dtype=None, shape=None, formats=None,
nn = len(descr[k].shape)
testshape = obj.shape[:len(obj.shape) - nn]
if testshape != shape:
- raise ValueError, "array-shape mismatch in array %d" % k
+ raise ValueError("array-shape mismatch in array %d" % k)
_array = recarray(shape, descr)
View
4 numpy/core/src/multiarray/testcalcs.py
@@ -41,12 +41,12 @@ def days_from_ymd(year, month, day):
# Negative month values indicate months relative to the years end */
if (month < 0): month += 13
if not (month >= 1 and month<=12):
- raise ValueError, "month out of range (1-21): %d" % month
+ raise ValueError("month out of range (1-21): %d" % month)
# Negative values indicate days relative to the months end */
if (day < 0): day += days_in_month[leap][month - 1] + 1
if not (day >= 1 and day <= days_in_month[leap][month-1]):
- raise ValueError, "day out of range: %d" % day
+ raise ValueError("day out of range: %d" % day)
# Number of days between Dec 31, (year - 1) and Dec 31, 1969
# (can be negative).
View
6 numpy/ctypeslib.py
@@ -166,13 +166,13 @@ def from_param(cls, obj):
raise TypeError("argument must be an ndarray")
if cls._dtype_ is not None \
and obj.dtype != cls._dtype_:
- raise TypeError, "array must have data type %s" % cls._dtype_
+ raise TypeError("array must have data type %s" % cls._dtype_)
if cls._ndim_ is not None \
and obj.ndim != cls._ndim_:
- raise TypeError, "array must have %d dimension(s)" % cls._ndim_
+ raise TypeError("array must have %d dimension(s)" % cls._ndim_)
if cls._shape_ is not None \
and obj.shape != cls._shape_:
- raise TypeError, "array must have shape %s" % str(cls._shape_)
+ raise TypeError("array must have shape %s" % str(cls._shape_))
if cls._flags_ is not None \
and ((obj.flags.num & cls._flags_) != cls._flags_):
raise TypeError, "array must have flags %s" % \
View
4 numpy/dual.py
@@ -49,14 +49,14 @@
def register_func(name, func):
if name not in __all__:
- raise ValueError, "%s not a dual function." % name
+ raise ValueError("%s not a dual function." % name)
f = sys._getframe(0).f_globals
_restore_dict[name] = f[name]
f[name] = func
def restore_func(name):
if name not in __all__:
- raise ValueError, "%s not a dual function." % name
+ raise ValueError("%s not a dual function." % name)
try:
val = _restore_dict[name]
except KeyError:
View
2 numpy/f2py/crackfortran.py
@@ -399,7 +399,7 @@ def readfortrancode(ffile,dowithline=show,istop=1):
ll=l
cont=(r is not None)
else:
- raise ValueError,"Flag sourcecodeform must be either 'fix' or 'free': %s"%`sourcecodeform`
+ raise ValueError("Flag sourcecodeform must be either 'fix' or 'free': %s"%`sourcecodeform`)
filepositiontext='Line #%d in %s:"%s"\n\t' % (fin.filelineno()-1,currentfilename,l1)
m=includeline.match(origfinalline)
if m:
View
2 numpy/f2py/f2py2e.py
@@ -378,7 +378,7 @@ def run_main(comline_list):
if postlist[i]['block']!='python module':
if 'python module' not in options:
errmess('Tip: If your original code is Fortran source then you must use -m option.\n')
- raise TypeError,'All blocks must be python module blocks but got %s'%(`postlist[i]['block']`)
+ raise TypeError('All blocks must be python module blocks but got %s'%(`postlist[i]['block']`))
auxfuncs.debugoptions=options['debug']
f90mod_rules.options=options
auxfuncs.wrapfuncs=options['wrapfuncs']
View
4 numpy/lib/npyio.py
@@ -233,7 +233,7 @@ def __getitem__(self, key):
else:
return bytes
else:
- raise KeyError, "%s is not a file in the archive" % key
+ raise KeyError("%s is not a file in the archive" % key)
def __iter__(self):
@@ -530,7 +530,7 @@ def _savez(file, args, kwds, compress):
for i, val in enumerate(args):
key = 'arr_%d' % i
if key in namedict.keys():
- raise ValueError, "Cannot use un-named variables and keyword %s" % key
+ raise ValueError("Cannot use un-named variables and keyword %s" % key)
namedict[key] = val
if compress:
View
8 numpy/linalg/linalg.py
@@ -643,7 +643,7 @@ def qr(a, mode='full'):
work = zeros((lwork,), t)
results = lapack_routine(m, n, a, m, tau, work, -1, 0)
if results['info'] != 0:
- raise LinAlgError, '%s returns %d' % (routine_name, results['info'])
+ raise LinAlgError('%s returns %d' % (routine_name, results['info']))
# do qr decomposition
lwork = int(abs(work[0]))
@@ -651,7 +651,7 @@ def qr(a, mode='full'):
results = lapack_routine(m, n, a, m, tau, work, lwork, 0)
if results['info'] != 0:
- raise LinAlgError, '%s returns %d' % (routine_name, results['info'])
+ raise LinAlgError('%s returns %d' % (routine_name, results['info']))
# economic mode. Isn't actually economic.
if mode[0] == 'e':
@@ -682,14 +682,14 @@ def qr(a, mode='full'):
work = zeros((lwork,), t)
results = lapack_routine(m, mn, mn, a, m, tau, work, -1, 0)
if results['info'] != 0:
- raise LinAlgError, '%s returns %d' % (routine_name, results['info'])
+ raise LinAlgError('%s returns %d' % (routine_name, results['info']))
# compute q
lwork = int(abs(work[0]))
work = zeros((lwork,), t)
results = lapack_routine(m, mn, mn, a, m, tau, work, lwork, 0)
if results['info'] != 0:
- raise LinAlgError, '%s returns %d' % (routine_name, results['info'])
+ raise LinAlgError('%s returns %d' % (routine_name, results['info']))
q = _fastCopyAndTranspose(result_t, a[:mn,:])
View
6 numpy/ma/mrecords.py
@@ -197,7 +197,7 @@ def __getattribute__(self, attr):
try:
res = fielddict[attr][:2]
except (TypeError, KeyError):
- raise AttributeError, "record array has no attribute %s" % attr
+ raise AttributeError("record array has no attribute %s" % attr)
# So far, so good...
_localdict = ndarray.__getattribute__(self, '__dict__')
_data = ndarray.view(self, _localdict['_baseclass'])
@@ -269,7 +269,7 @@ def __setattr__(self, attr, val):
try:
res = fielddict[attr][:2]
except (TypeError, KeyError):
- raise AttributeError, "record array has no attribute %s" % attr
+ raise AttributeError("record array has no attribute %s" % attr)
#
if val is masked:
_fill_value = _localdict['_fill_value']
@@ -619,7 +619,7 @@ def openfile(fname):
try:
f = open(fname)
except IOError:
- raise IOError, "No such file: '%s'" % fname
+ raise IOError("No such file: '%s'" % fname)
if f.readline()[:2] != "\\x":
f.seek(0, 0)
return f
View
2 numpy/matrixlib/defmatrix.py
@@ -995,7 +995,7 @@ def _from_string(str,gdict,ldict):
try:
thismat = gdict[col]
except KeyError:
- raise KeyError, "%s not found" % (col,)
+ raise KeyError("%s not found" % (col,))
coltup.append(thismat)
rowtup.append(concatenate(coltup,axis=-1))
View
2 numpy/oldnumeric/ma.py
@@ -622,7 +622,7 @@ def __array__ (self, t=None, context=None):
func, args, i = context
fills = ufunc_fills.get(func)
if fills is None:
- raise MAError, "%s not known to ma" % func
+ raise MAError("%s not known to ma" % func)
return self.filled(fills[i])
else: # Mask is all false
# Optimize to avoid future invocations of this section.

0 comments on commit e1a9692

Please sign in to comment.
Something went wrong with that request. Please try again.